Skip to content

Commit 197dcd0

Browse files
committed
Fix ariaDescribedBy attribute for inputs
Refs: #7162
1 parent 5e50f2e commit 197dcd0

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

packages/components/src/functional-component-wrappers/InputStateWrapper/InputStateWrapper.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ export type InputStateWrapperProps = Partial<InputProps> & {
3535

3636
/**
3737
* @param state
38+
* @param other
3839
* @param customSuggestions - Set to true when a custom implementation for _suggestions is provided. Omits the native datalist.
3940
*/
40-
function getInputProps(state: InputState, customSuggestions?: boolean): InputProps {
41-
const { ariaDescribedBy } = getRenderStates(state);
41+
function getInputProps(state: InputState, other: Partial<InputProps>, customSuggestions?: boolean): InputProps {
42+
const renderStates = getRenderStates(state);
43+
const ariaDescribedBy = [...renderStates.ariaDescribedBy, ...(other.ariaDescribedBy ?? [])];
4244

4345
const props: InputProps = {
4446
id: state._id,
@@ -47,8 +49,6 @@ function getInputProps(state: InputState, customSuggestions?: boolean): InputPro
4749
accessKey: state._accessKey,
4850
disabled: state._disabled,
4951
name: state._name,
50-
51-
ariaDescribedBy: ariaDescribedBy,
5252
};
5353

5454
if ('_type' in state) props.type = state._type;
@@ -76,11 +76,15 @@ function getInputProps(state: InputState, customSuggestions?: boolean): InputPro
7676
}
7777
}
7878

79-
return props;
79+
return {
80+
...props,
81+
...other,
82+
ariaDescribedBy,
83+
};
8084
}
8185

8286
const InputStateWrapper: FC<InputStateWrapperProps> = ({ state, customSuggestions, ...other }) => {
83-
return <KolInputFc {...getInputProps(state, customSuggestions)} {...other} />;
87+
return <KolInputFc {...getInputProps(state, other, customSuggestions)} />;
8488
};
8589

8690
export default InputStateWrapper;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`KolFormFieldCounterFc should render correctly 1`] = `
4-
<span aria-hidden="true" class="custom-class kol-form-field__counter" data-testid="input-counter">
4+
<span aria-hidden="true" class="kol-form-field__counter" data-testid="input-counter">
55
kol-character-limit-remaining
66
</span>
77
`;

packages/components/src/functional-components/FormFieldCounter/tests/snapshot.test.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,10 @@ const maxLength = 10;
88

99
describe('KolFormFieldCounterFc', () => {
1010
it('should render correctly', async () => {
11-
const classNames = 'custom-class';
1211
const page = await renderFunctionalComponentToSpecPage(() => (
13-
<KolFormFieldCounterFc
14-
id="test-id"
15-
currentLength={currentLength}
16-
currentLengthDebounced={currentLengthDebounced}
17-
maxLength={maxLength}
18-
class={classNames}
19-
/>
12+
<KolFormFieldCounterFc id="test-id" currentLength={currentLength} currentLengthDebounced={currentLengthDebounced} maxLength={maxLength} />
2013
));
2114

2215
expect(page.root).toMatchSnapshot();
2316
});
24-
25-
it('should set the correct class names', async () => {
26-
const classNames = 'custom-class';
27-
const page = await renderFunctionalComponentToSpecPage(() => (
28-
<KolFormFieldCounterFc
29-
id="test-id"
30-
currentLength={currentLength}
31-
currentLengthDebounced={currentLengthDebounced}
32-
maxLength={maxLength}
33-
class={classNames}
34-
/>
35-
));
36-
37-
expect(page.root?.className).toContain('counter');
38-
expect(page.root?.className).toContain(classNames);
39-
});
4017
});

0 commit comments

Comments
 (0)