Skip to content

Commit 4d9ffb1

Browse files
authored
fix(datepicker): apply id on label's htmlFor attribute (#284)
1 parent b3a7e3e commit 4d9ffb1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/__tests__/datepicker.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ describe('Basic datepicker', () => {
236236
expect(datePickerInput.value).toBe('');
237237
});
238238

239+
it('should be accessible when id is provided', () => {
240+
const { getByLabelText, getByText } = setup({
241+
id: 'click-me',
242+
label: 'Click me',
243+
});
244+
245+
fireEvent.click(getByLabelText('Click me'));
246+
expect(getByText('Today')).toBeTruthy();
247+
});
248+
239249
describe('clearOnSameDateClick', () => {
240250
it('reset its state when prop is true', () => {
241251
const { datePickerInput, getByText, openDatePicker } = setup({

src/components/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const CustomInput = React.forwardRef<Input, InputProps>((props, ref) => {
1818

1919
return (
2020
<Form.Field>
21-
{label && <label>{label}</label>}
21+
{label && <label htmlFor={rest.id as string | undefined}>{label}</label>}
2222
<Input
2323
data-testid="datepicker-input"
2424
{...rest}

0 commit comments

Comments
 (0)