LOS ANGELES — President Donald Trump does not have to disclose his tax returns to appear as a candidate on California’s primary ballot next spring, the state Supreme Court ruled unanimously Thursday.

The law, the first of its kind in the nation and aimed squarely at Trump, violates the state constitution’s “specification of an inclusive open presidential primary ballot,” the court said.

“Ultimately, it is the voters who must decide whether the refusal of a ‘recognized candidate throughout the nation or throughout California for the office of President of the United States’ to make such information available to the public will have consequences at the ballot box,” Chief Justice Tani Cantil-Sakauye wrote in the 7-0 decision.

Trump has broken with tradition among presidential candidates by refusing to disclose his financial information.

A U.S. judge had temporarily blocked the state law in response to a different lawsuit and the high court ruled quickly because the deadline to file tax returns for getting on the primary ballot is next week.

The state Republican Party and chairwoman Jessica Millan Patterson challenged the bill signed into law this year by Democratic Gov. Gavin Newsom because it singled out Trump.

“Today’s ruling is a victory for every California voter,” Patterson said in a statement. “We are pleased that the courts saw through the Democrats’ petty partisan maneuvers and saw this law for what it is — an unconstitutional attempt to suppress Republican voter turnout.”

The state defended the law, saying release of tax returns gave voters important information to weigh candidates’ financial status.

Sen. Mike McGuire, a Democrat who authored the bill, said it was a simple requirement for candidates to meet and provided transparency and accountability.

“Today’s decision flies in the face of what the American people have come to expect from presidential candidates — transparency,” McGuire said. “Every presidential candidate for the past 40 years has released their tax returns, with the exception of the current occupant of the White House. If he has nothing to hide, why wouldn’t he release them?”

The law would have required candidates for president or governor to file copies of personal income tax returns dating back five years. Refusal to do so would keep them off the state’s primary ballot, but not apply to general elections.

The ruling does not apply to the requirement for gubernatorial candidates, a governor’s spokesman said.

“Governments have a moral duty to restore public confidence in government and ensure leaders seeking the highest offices meet minimal standards,” Newsom spokesman Jesse Melgar said in a statement. “Congress and other states can and should take action to require presidential candidates to disclose their tax returns.”

Skeptical justices at a hearing earlier this month questioned whether such a law could open the door to future requirements of medical and psychiatric records or school report cards.

Attorney Thomas Hiltachk argued for the state GOP that the law violated a 1972 voter-approved amendment guaranteeing that all recognized candidates must be on the ballot.

Republicans also said it would lower voter turnout in the primary, hurting Republican legislative and congressional candidates’ chances of reaching the general election.

Trump has cited an ongoing Internal Revenue Service audit in refusing to release his returns.

Other courts have ordered Trump to turn over his tax returns to a Manhattan grand jury and the House of Representatives for separate investigations.

The U.S. Supreme Court is weighing whether to intervene in the demand from a congressional committee or to let a lower appeals court ruling stand that would require disclosure of Trump’s taxes.

Trump has also asked the high court to block a subpoena from a New York prosecutor for his tax returns.

Manhattan District Attorney Cyrus R. Vance Jr. is seeking the records in an investigation that includes alleged payments to buy the silence of adult film actress Stormy Daniels and Playboy centerfold Karen McDougal, both of whom claim they had affairs with the president before the 2016 presidential election. Trump has denied the allegations