HARTFORD, Conn.: Transgender inmates in Connecticut will soon become the first in the nation to have a legal right to be housed in a prison that matches the gender with which they identify, a law being lauded by civil rights advocates as groundbreaking.

In addition to housing, it gives inmates the right to be searched by a corrections officer who matches their self-identified gender, to be addressed in a manner consistent with their gender identity and have access to commissary items, like clothing, that match their gender identity.

“This is a really big deal,” said David McGuire, executive director of the American Civil Liberties Union of Connecticut. “It is, in our mind, the most protective transgender policy and law in the country.”

The legislation passed this spring as part of a larger bill that also dealt with the rights of pregnant inmates.

The law codifies much of a directive the Department of Correction put in place in February, which outlines procedures for assessing and dealing with gender nonconforming inmates.

That directive was formed, in part, in response to a 2014 case involving a transgender teen, who ended up being held at an adult prison for women because Connecticut could not figure out where to place her, said Mike Lawlor, the governor’s undersecretary for criminal justice policy and planning.

It is designed to dovetail with state law that bans discrimination in public places on the basis of gender identity or expression and the federal Prison Rape Elimination Act, Lawlor said.

“I’m sure there will be people who will say, ‘So how does this work?’ ” he said. “ ‘If you are a guy, do you just say you’re a woman and you get to go to a woman’s prison?’ No. There is a very elaborate analysis, psychological and otherwise.”

The law, which goes into effect July 1, requires a diagnosis of gender dysphoria or a legal identification that matches the person’s gender identity. The “presumptive placement” can be changed if prison officials determine it would present problems, the law states.

The Bureau of Justice Statistics estimated there are 3,200 transgender inmates in the nation’s prisons and jails.