HARTFORD, Conn. (AP) — 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 also gives inmates the right to be searched by a correction officer who matches their self-identified gender, to be addressed in a manner consistent with their gender identity and have access to commissary items, such as clothing, that matches their gender identity.

"This is a really big deal," said David McGuire, executive director of the ACLU 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 non-conforming inmates.

That directive was formed, in part, in response to a 2014 case involving a transgender Connecticut teen, who ended up being held for a time at an adult prison for women because the state 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, according to the law.

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

The department's directive allows inmates who had been receiving hormone therapy to continue getting it in prison. But the law does not address whether inmates can receive gender reassignment surgery while in prison.

Jennifer L. Levi, the transgender rights project director with GLAD — GLBTQ Legal Advocates & Defenders, based in Boston — said she expects the legislation will serve as a model for other states.

It's important, she said, because it comes as the federal prison system rolls back Obama-era protections for transgender inmates. She said prisoners who are not treated according to their gender identities are often subjected to physical and mental abuse.

"There are many states for which transgender people are basically serving double sentences," she said. "One for the underlying crime for which they've been convicted of and the other just for being transgender."

Luci Karma served a year in the Bridgeport Correctional Institution for assault about five years ago.

The 40-year-old Norwalk native who identifies as a woman was given a choice entering prison: serve time in the general population of a male facility or be placed in isolated segregation in the women's prison.

Karma said she chose the male prison, but was constantly subjected to harassment from both prisoners and prison staff.

She said she hopes the new law will help, but believes real change will come only with a general acceptance in society of transgender people.

"The answer is consideration and thoughtfulness, and hopefully that's what is going to happen," she said. "All you can ask for is that people be considerate and thoughtful of who I am as a person. But, if my very existence threatens you or causes you to want to be aggressive, that's always going to be a problem, no matter where they put you."

Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.