A federal judge on Friday blocked the University of North Carolina (UNC) from enforcing a state law that restricts transgender bathroom use.

U.S. District Judge Thomas Schroeder blocked UNC officials from enforcing a key provision of House Bill 2 that prohibits transgender people from using the bathroom of their choice in public buildings, including schools.

Schroeder blocked UNC from enforcing the law until the case is settled, BuzzFeed News reported. UNC had previously said that it would not enforce the law.

The American Civil Liberties Union (ACLU) and Lambda Legal filed the lawsuit after Republican lawmakers approved and Governor Pat McCrory signed House Bill 2 during a one-day special session in March. The law also blocks cities and municipalities from approving LGBT protections.

Despite a public backlash to the law – including loss of the NBA's All-Star Game – lawmakers ended this year's legislative session without repealing it.

“Instead of wasting tens of thousands of taxpayer dollars trying to defend the indefensible, Governor McCrory and state lawmakers should be working towards fully repealing HB2,” said HRC Legal Director Sarah Warbelow.

McCrory is in a tight race against Roy Cooper, the state's Democratic attorney general. A poll released Wednesday shows Cooper with a 9-point lead among likely voters in the state. Pollsters also found that a majority (55%) of voters disapprove of HB2.

(Related: At Donald Trump rally, Pat McCrory ridicules transgender rights.)