Skip to content

Commit

Permalink
EPMRPP-93028 || Use React 18th 'useId' hook
Browse files Browse the repository at this point in the history
  • Loading branch information
maria-hambardzumian committed Oct 8, 2024
1 parent 66101d6 commit c121c74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
KeyboardEventHandler,
ChangeEventHandler,
HTMLAttributes,
useId,
} from 'react';
import { KeyCodes } from '@common/constants/keyCodes';
import styles from './checkbox.module.scss';
Expand Down Expand Up @@ -35,6 +36,7 @@ export const Checkbox: FC<CheckboxProps> = ({
...rest
}): ReactElement => {
const inputRef = useRef<HTMLInputElement | null>(null);
const checkboxLabelId = useId();

const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
const { keyCode } = event;
Expand All @@ -53,7 +55,7 @@ export const Checkbox: FC<CheckboxProps> = ({

return (
<label
id="rp-ui-kit-checkbox-label"
id={checkboxLabelId}
className={cx('checkbox', className, {
disabled,
})}
Expand Down
4 changes: 3 additions & 1 deletion src/components/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FC,
ReactElement,
KeyboardEvent,
useId,
} from 'react';
import classNames from 'classnames/bind';
import { KeyCodes } from '@common/constants/keyCodes';
Expand Down Expand Up @@ -40,6 +41,7 @@ export const Radio: FC<RadioProps> = ({
...rest
}): ReactElement => {
const inputRef = useRef<HTMLInputElement | null>(null);
const radioLabelId = useId();

const isChecked = String(option.value) === String(value);

Expand All @@ -62,7 +64,7 @@ export const Radio: FC<RadioProps> = ({
return (
// eslint-disable-next-line
<label
id="rp-ui-kit-radio-label"
id={radioLabelId}
className={cx(className, 'radio-button', {
disabled: option.disabled,
})}
Expand Down
8 changes: 3 additions & 5 deletions src/components/toggle/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
KeyboardEventHandler,
ReactElement,
ReactNode,
useId,
useRef,
} from 'react';
import { KeyCodes } from '@common/constants/keyCodes';
Expand All @@ -32,6 +33,7 @@ export const Toggle: FC<ToggleProps> = ({
...rest
}): ReactElement => {
const inputRef = useRef<HTMLInputElement | null>(null);
const toggleLabelId = useId();

const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
const { keyCode } = event;
Expand All @@ -49,11 +51,7 @@ export const Toggle: FC<ToggleProps> = ({
};

return (
<label
id="rp-ui-kit-toggle-label"
title={title}
className={cx('toggle', className, { disabled })}
>
<label id={toggleLabelId} title={title} className={cx('toggle', className, { disabled })}>
<input
ref={inputRef}
tabIndex={disabled ? -1 : 0}
Expand Down

0 comments on commit c121c74

Please # to comment.