Skip to content

Commit c79b4fb

Browse files
authored
fix(verificationCode): add htmlFor for label (#5573)
1 parent 6d9a56d commit c79b4fb

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

.changeset/dark-pugs-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": patch
3+
---
4+
5+
Add htmlFor on label for VerificationCode

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build:
1414
strategy:
1515
matrix:
16-
node: ["22"]
16+
node: ["22", "24"]
1717
runs-on: ubuntu-24.04
1818
env:
1919
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
@@ -143,7 +143,7 @@ jobs:
143143
needs: [typecheck, format]
144144
strategy:
145145
matrix:
146-
node: ["22"]
146+
node: ["22", "24"]
147147
steps:
148148
- uses: actions/checkout@v5
149149
with:

packages/form/src/components/VerificationCodeField/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ exports[`verificationCodeField > should render correctly 1`] = `
100100
class="uv_toi52u0 uv_toi52u3j uv_toi52u2j uv_toi52u7d uv_toi52u1v uv_toi52u5d"
101101
>
102102
<label
103-
class="uv_17td3g92 uv_m4c9ow0 uv_m4c9ow2 uv_m4c9ow4 uv_m4c9ow6 uv_m4c9ow8 uv_m4c9owb uv_m4c9owi uv_m4c9owq uv_m4c9ow1b uv_m4c9ow20 uv_m4c9ow3c"
103+
class="uv_17td3g91 uv_m4c9ow0 uv_m4c9ow2 uv_m4c9ow4 uv_m4c9ow6 uv_m4c9ow8 uv_m4c9owb uv_m4c9owi uv_m4c9owq uv_m4c9ow1b uv_m4c9ow20 uv_m4c9ow3c"
104+
for="verification-code-input-0"
105+
id="verification-code-input-label"
104106
>
105107
Code
106108
</label>

packages/ui/src/components/VerificationCode/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,9 @@ exports[`verificationCode > render correctly with label 1`] = `
559559
class="emotion-0 emotion-1"
560560
>
561561
<label
562-
class="styles_default__17td3g92 style__m4c9ow0 style_strikeThrough_false__m4c9ow2 style_italic_false__m4c9ow4 style_underline_false__m4c9ow6 style_oneLine_false__m4c9ow8 style_sentiment_neutral__m4c9owb style_prominence_default__m4c9owi style_variant_bodyStrong__m4c9owq style_disabled_false__m4c9ow1b style_undefined_compound_24__m4c9ow20 style_undefined_compound_72__m4c9ow3c"
562+
class="styles_htmlFor__17td3g91 style__m4c9ow0 style_strikeThrough_false__m4c9ow2 style_italic_false__m4c9ow4 style_underline_false__m4c9ow6 style_oneLine_false__m4c9ow8 style_sentiment_neutral__m4c9owb style_prominence_default__m4c9owi style_variant_bodyStrong__m4c9owq style_disabled_false__m4c9ow1b style_undefined_compound_24__m4c9ow20 style_undefined_compound_72__m4c9ow3c"
563+
for="«re»-0"
564+
id="«re»-label"
563565
>
564566
test
565567
</label>
@@ -718,7 +720,9 @@ exports[`verificationCode > render correctly with labelDescription 1`] = `
718720
class="styles__toi52u0 styles_alignItems_center_xxsmall__toi52u3d styles_flexDirection_row_xxsmall__toi52u2j styles_flexWrap_nowrap_xxsmall__toi52u7d styles_gap_0.5rem_xxsmall__toi52u7 styles_justifyContent_normal_xxsmall__toi52u5d"
719721
>
720722
<label
721-
class="styles_default__17td3g92 style__m4c9ow0 style_strikeThrough_false__m4c9ow2 style_italic_false__m4c9ow4 style_underline_false__m4c9ow6 style_oneLine_false__m4c9ow8 style_sentiment_neutral__m4c9owb style_prominence_default__m4c9owi style_variant_bodyStrong__m4c9owq style_disabled_false__m4c9ow1b style_undefined_compound_24__m4c9ow20 style_undefined_compound_72__m4c9ow3c"
723+
class="styles_htmlFor__17td3g91 style__m4c9ow0 style_strikeThrough_false__m4c9ow2 style_italic_false__m4c9ow4 style_underline_false__m4c9ow6 style_oneLine_false__m4c9ow8 style_sentiment_neutral__m4c9owb style_prominence_default__m4c9owi style_variant_bodyStrong__m4c9owq style_disabled_false__m4c9ow1b style_undefined_compound_24__m4c9ow20 style_undefined_compound_72__m4c9ow3c"
724+
for="«rn»-0"
725+
id="«rn»-label"
722726
>
723727
test
724728
</label>

packages/ui/src/components/VerificationCode/__tests__/index.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ describe('verificationCode', () => {
128128

129129
test('render correctly with label', () => {
130130
const { asFragment } = renderWithTheme(<VerificationCode label="test" />)
131+
132+
const code = screen.getByLabelText('test')
133+
expect(code).toBeInTheDocument()
134+
expect(code).toBeEnabled()
131135
expect(asFragment()).toMatchSnapshot()
132136
})
133137

packages/ui/src/components/VerificationCode/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const VerificationCode = ({
179179
success,
180180
}: VerificationCodeProps) => {
181181
const uniqueId = useId()
182+
const id = inputId || uniqueId
182183
const valuesArray = Object.assign(new Array(fields).fill(''), [
183184
...initialValue.substring(0, fields),
184185
])
@@ -337,6 +338,8 @@ export const VerificationCode = ({
337338
<FieldSet className={className} data-testid={dataTestId}>
338339
{label || labelDescription ? (
339340
<Label
341+
htmlFor={`${id}-0`}
342+
id={`${id}-label`}
340343
labelDescription={labelDescription}
341344
required={required}
342345
size={size === 'xlarge' ? 'large' : size}
@@ -354,7 +357,7 @@ export const VerificationCode = ({
354357
data-success={!!success}
355358
data-testid={index}
356359
disabled={disabled}
357-
id={`${inputId || uniqueId}-${index}`}
360+
id={`${id}-${index}`}
358361
inputSize={size}
359362
key={`field-${index}`}
360363
onChange={inputOnChange(index)}

0 commit comments

Comments
 (0)