Skip to content

Commit f6ae4ce

Browse files
committed
refactor(next): simplify Switch id handling with useId
1 parent b34f748 commit f6ae4ce

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • packages/eds-core-react/src/components/next/Switch

packages/eds-core-react/src/components/next/Switch/Switch.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { forwardRef, useState, useCallback } from 'react'
2-
import { Field, useFieldIds } from '../Field'
1+
import { forwardRef, useState, useCallback, useId } from 'react'
2+
import { Field } from '../Field'
33
import type { SwitchProps } from './Switch.types'
44

55
export const Switch = forwardRef<HTMLInputElement, SwitchProps>(function Switch(
66
{
77
label,
88
disabled,
99
className,
10-
id: providedId,
10+
id,
1111
checked: controlledChecked,
1212
defaultChecked,
1313
onChange,
1414
...rest
1515
},
1616
ref,
1717
) {
18-
const { inputId } = useFieldIds(providedId)
18+
const generatedId = useId()
19+
const inputId = id ?? generatedId
1920

2021
// Track checked state for dynamic color appearance
2122
const isControlled = controlledChecked !== undefined

0 commit comments

Comments
 (0)