Skip to content

Commit f0ce4de

Browse files
Remove unsupported autoSelectNext date input feature
1 parent c2e2302 commit f0ce4de

File tree

3 files changed

+1
-85
lines changed

3 files changed

+1
-85
lines changed

src/components/form-elements/date-input/DateInput.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export type DateInputChangeEvent = ChangeEvent<
2020
interface DateInputProps
2121
extends Omit<HTMLProps<HTMLDivElement>, 'value' | 'defaultValue'>,
2222
FormElementProps {
23-
autoSelectNext?: boolean;
2423
value?: Partial<DateInputValue>;
2524
defaultValue?: Partial<DateInputValue>;
2625
onChange?: (e: DateInputChangeEvent) => void;
@@ -29,7 +28,6 @@ interface DateInputProps
2928
type InputType = 'day' | 'month' | 'year';
3029

3130
const DateInputComponent = ({
32-
autoSelectNext,
3331
children,
3432
onChange,
3533
value,
@@ -54,19 +52,7 @@ const DateInputComponent = ({
5452
return setInternalDate(newState);
5553
}, [value]);
5654

57-
const handleFocusNextInput = (inputType: InputType, value: string): void => {
58-
if (!autoSelectNext) return;
59-
if (inputType === 'day' && value.length === 2 && monthRef) {
60-
monthRef.focus();
61-
} else if (inputType === 'month' && value.length === 2 && yearRef) {
62-
yearRef.focus();
63-
}
64-
};
65-
6655
const handleChange = (inputType: InputType, event: ChangeEvent<HTMLInputElement>): void => {
67-
handleFocusNextInput(inputType, event.target.value);
68-
event.stopPropagation();
69-
7056
const newEventValue: DateInputValue = {
7157
...internalDate,
7258
[inputType]: event.target.value,
@@ -93,7 +79,7 @@ const DateInputComponent = ({
9379
{...rest}
9480
>
9581
{/* eslint-disable-next-line @typescript-eslint/no-unused-vars */}
96-
{({ className, name, id, error, autoSelectNext, ...restRenderProps }) => {
82+
{({ className, name, id, error, ...restRenderProps }) => {
9783
const contextValue: IDateInputContext = {
9884
id,
9985
name,

src/components/form-elements/date-input/__tests__/DateInput.test.tsx

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,6 @@ describe('DateInput', () => {
99
expect(container).toMatchSnapshot();
1010
});
1111

12-
it.each`
13-
autoSelectNext | inputValue | monthFocusExpected
14-
${false} | ${'1'} | ${false}
15-
${false} | ${'11'} | ${false}
16-
${true} | ${'1'} | ${false}
17-
${true} | ${'11'} | ${true}
18-
`(
19-
'When autoSelectNext is $autoSelectNext, the day input value is $inputValue, then month focus is expected to be $monthFocusExpected',
20-
({ autoSelectNext, inputValue, monthFocusExpected }) => {
21-
const { container } = render(
22-
<DateInput id="testInput" name="testInput" autoSelectNext={autoSelectNext} />,
23-
);
24-
25-
const dayInput = container.querySelector('#testInput-day')!;
26-
const monthInput = container.querySelector('#testInput-month')!;
27-
28-
expect(monthInput).not.toHaveFocus();
29-
30-
fireEvent.change(dayInput, { target: { value: inputValue } });
31-
32-
if (monthFocusExpected) {
33-
expect(monthInput).toHaveFocus();
34-
} else {
35-
expect(monthInput).not.toHaveFocus();
36-
}
37-
},
38-
);
39-
40-
it.each`
41-
autoSelectNext | inputValue | yearFocusExpected
42-
${false} | ${'1'} | ${false}
43-
${false} | ${'11'} | ${false}
44-
${true} | ${'1'} | ${false}
45-
${true} | ${'11'} | ${true}
46-
`(
47-
'When autoSelectNext is $autoSelectNext, the day input value is $inputValue, then year focus is expected to be $yearFocusExpected',
48-
({ autoSelectNext, inputValue, yearFocusExpected }) => {
49-
const { container } = render(
50-
<DateInput id="testInput" name="testInput" autoSelectNext={autoSelectNext} />,
51-
);
52-
53-
const monthInput = container.querySelector('#testInput-month')!;
54-
const yearInput = container.querySelector('#testInput-year')!;
55-
56-
expect(yearInput).not.toHaveFocus();
57-
58-
fireEvent.change(monthInput, { target: { value: inputValue } });
59-
60-
if (yearFocusExpected) {
61-
expect(yearInput).toHaveFocus();
62-
} else {
63-
expect(yearInput).not.toHaveFocus();
64-
}
65-
},
66-
);
67-
6812
it('Invokes the provided onChange function prop if provided', () => {
6913
let onChangeParam: DateInputChangeEvent | null = null;
7014
const onChange = jest.fn().mockImplementation((val) => (onChangeParam = val));

stories/Form Elements/DateInput.stories.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ export const StandardWithError: Story = {
6060
),
6161
};
6262

63-
export const StandardWithAutoSelect: Story = {
64-
render: () => (
65-
<div style={{ padding: 20 }}>
66-
<h2>Scenario: autoSelectNext prop is set to enable the auto focus functionality</h2>
67-
<h5>Expected Behaviour</h5>
68-
<ul className="nhsuk-hint">
69-
<li>When day field has 2 or month field has 2 characters, the next field is focused</li>
70-
</ul>
71-
<h5>Component</h5>
72-
<DateInput autoSelectNext />
73-
</div>
74-
),
75-
};
76-
7763
export const PrePopulatedIndividualComponents: Story = {
7864
render: () => {
7965
const defaultValue = { day: '20', month: '09', year: '1996' };

0 commit comments

Comments
 (0)