import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "./select"; import { US_STATES, normalizeUsState } from "../../utils/usStates"; export interface StateSelectProps { /** The stored `Address.state`. May be anything at all - records predate this control. */ value: string | undefined; /** Receives a canonical USPS code, or `undefined` when the field is cleared. */ onChange: (next: string | undefined) => void; disabled?: boolean; className?: string; /** Accessible name. Both call sites sit in a row of unlabelled address boxes. */ "aria-label"?: string; } /** * The one place a state is chosen. Both address call sites use this rather than each growing a list, * because two lists is how they drift apart. * * A picker rather than a validated text box on purpose: `Address.state` has no binding in FHIR and no * server check is possible, so refusal has to be structural. A rule that merely rejects on save is a * rule a later change can loosen without anyone noticing. */ export const StateSelect = ({ value, onChange, disabled, className, "aria-label": ariaLabel = "State", }: StateSelectProps) => { const canonical = normalizeUsState(value); const stored = (value ?? "").trim(); // A record already holding a bad state has to remain correctable, and it has to keep SHOWING what // it holds while it is. Dropping the unrecognised value would blank the field, which reads as // "no state on file" and quietly loses the only clue to what was meant. const unrecognised = stored && !canonical ? stored : undefined; return ( ); }; export default StateSelect;