Skip to content

Commit 1dffb6a

Browse files
author
Kubit
committed
Fix extraAriaLabelledBy prop on Input component
Now, if not have a value, the value will be undefined
1 parent 7998ff6 commit 1dffb6a

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/components/input/__tests__/aria.utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ describe('Utils aria', () => {
1717
errorMessageId,
1818
state,
1919
})
20-
).toBe(' 1234 56789');
20+
).toBe(' 56789 1234');
2121
});
2222
});

src/components/input/__tests__/input.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function backspace(element) {
5656

5757
const writeText = jest.fn();
5858

59-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
6059
Object.assign(navigator, {
6160
clipboard: {
6261
writeText,
@@ -504,4 +503,13 @@ describe('New Input Component', () => {
504503
expect(container).toHTMLValidate();
505504
expect(results).toHaveNoViolations();
506505
});
506+
it('Should have ariaLabelledby when is set the prop extraAriaLabelledBy', async () => {
507+
const extraAriabelledBy = 'extraAriaLabelledBy';
508+
const { getByTestId } = renderProvider(
509+
<Input {...commonProps} extraAriaLabelledBy={extraAriabelledBy} />
510+
);
511+
512+
const input = getByTestId(`${commonProps.dataTestId}Input`);
513+
expect(input).toHaveAttribute('aria-labelledby', extraAriabelledBy);
514+
});
507515
});

src/components/input/inputStandAlone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const InputStandAloneComponent = (
7575
}
7676
aria-haspopup={props['aria-haspopup']}
7777
aria-invalid={hasError(state)}
78-
aria-labelledby={props.extraAriaLabelledBy}
78+
aria-labelledby={props.extraAriaLabelledBy ? props.extraAriaLabelledBy : undefined}
7979
{...ariaProps}
8080
aria-describedby={buildAriaDescribedBy({
8181
ariaDescribedBy: props['aria-describedby'],

src/components/input/utils/aria.utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ export const buildAriaDescribedBy = ({
2222
if (ariaDescribedBy) {
2323
res += ` ${ariaDescribedBy}`;
2424
}
25-
if (helpMessageId && helpMessage) {
26-
res += ` ${helpMessageId}`;
27-
}
28-
2925
if (errorMessageId && errorMessage && hasError(state)) {
3026
res += ` ${errorMessageId}`;
3127
}
28+
if (helpMessageId && helpMessage) {
29+
res += ` ${helpMessageId}`;
30+
}
3231
return res;
3332
};

0 commit comments

Comments
 (0)