Skip to content

Commit d016030

Browse files
authored
Merge pull request #2137 from dxc-technology/jialecl-textInput-ariaLabel
ariaLabel added to input components
2 parents 980cbf7 + 19cfa99 commit d016030

File tree

13 files changed

+80
-4
lines changed

13 files changed

+80
-4
lines changed

apps/website/screens/components/date-input/code/DateInputCodePage.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ const sections = [
236236
<td>Reference to the component.</td>
237237
<td>-</td>
238238
</tr>
239+
<tr>
240+
<td>ariaLabel</td>
241+
<td>
242+
<TableCode>string</TableCode>
243+
</td>
244+
<td>
245+
Specifies a string to be used as the name for the date input element when no <Code>label</Code> is
246+
provided.
247+
</td>
248+
<td>'Date input'</td>
249+
</tr>
239250
</tbody>
240251
</DxcTable>
241252
),

apps/website/screens/components/number-input/code/NumberInputCodePage.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ const sections = [
257257
<td>Reference to the component.</td>
258258
<td>-</td>
259259
</tr>
260+
<tr>
261+
<td>ariaLabel</td>
262+
<td>
263+
<TableCode>string</TableCode>
264+
</td>
265+
<td>
266+
Specifies a string to be used as the name for the number input element when no <Code>label</Code> is
267+
provided.
268+
</td>
269+
<td>'Number input'</td>
270+
</tr>
260271
</tbody>
261272
</DxcTable>
262273
),

apps/website/screens/components/password-input/code/PasswordInputCodePage.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ const sections = [
204204
<td>Reference to the component.</td>
205205
<td>-</td>
206206
</tr>
207+
<tr>
208+
<td>ariaLabel</td>
209+
<td>
210+
<TableCode>string</TableCode>
211+
</td>
212+
<td>
213+
Specifies a string to be used as the name for the password input element when no <Code>label</Code> is
214+
provided.
215+
</td>
216+
<td>'Password input'</td>
217+
</tr>
207218
</tbody>
208219
</DxcTable>
209220
),

apps/website/screens/components/text-input/code/TextInputCodePage.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ const sections = [
330330
<td>Reference to the component.</td>
331331
<td>-</td>
332332
</tr>
333+
<tr>
334+
<td>ariaLabel</td>
335+
<td>
336+
<TableCode>string</TableCode>
337+
</td>
338+
<td>
339+
Specifies a string to be used as the name for the textInput element when no <Code>label</Code> is
340+
provided.
341+
</td>
342+
<td>'Text input'</td>
343+
</tr>
333344
</tbody>
334345
</DxcTable>
335346
),

packages/lib/src/date-input/DateInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const DxcDateInput = forwardRef<RefType, DateInputPropsType>(
7373
margin,
7474
size,
7575
tabIndex,
76+
ariaLabel = "Date input",
7677
},
7778
ref
7879
): JSX.Element => {
@@ -260,6 +261,7 @@ const DxcDateInput = forwardRef<RefType, DateInputPropsType>(
260261
size={size}
261262
tabIndex={tabIndex}
262263
ref={dateRef}
264+
ariaLabel={ariaLabel}
263265
/>
264266
</Popover.Trigger>
265267
<Popover.Portal>

packages/lib/src/date-input/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ type Props = {
9393
* Value of the tabindex attribute.
9494
*/
9595
tabIndex?: number;
96+
/**
97+
* Specifies a string to be used as the name for the date input element when no `label` is provided.
98+
*/
99+
ariaLabel?: string;
96100
};
97101

98102
export type DateType = { day: number; month: number; year: number };

packages/lib/src/number-input/NumberInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const DxcNumberInput = forwardRef<RefType, NumberInputPropsType>(
2828
margin,
2929
size,
3030
tabIndex,
31+
ariaLabel = "Number input",
3132
},
3233
ref
3334
) => {
@@ -77,6 +78,7 @@ const DxcNumberInput = forwardRef<RefType, NumberInputPropsType>(
7778
size={size}
7879
tabIndex={tabIndex}
7980
ref={ref}
81+
ariaLabel={ariaLabel}
8082
/>
8183
</NumberInputContainer>
8284
</NumberInputContext.Provider>

packages/lib/src/number-input/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ type Props = {
111111
* Value of the tabindex attribute.
112112
*/
113113
tabIndex?: number;
114+
/**
115+
* Specifies a string to be used as the name for the number input element when no `label` is provided.
116+
*/
117+
ariaLabel?: string;
114118
};
115119

116120
export type NumberInputContextProps = {

packages/lib/src/password-input/PasswordInput.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ const setInputType = (type: string, element: HTMLDivElement | null) => {
88
element?.getElementsByTagName("input")[0]?.setAttribute("type", type);
99
};
1010

11-
const setAriaAttributes = (ariaExpanded: "true" | "false", ariaLabel: string, element: HTMLDivElement | null) => {
11+
const setAriaAttributes = (ariaExpanded: "true" | "false", element: HTMLDivElement | null) => {
1212
const buttonElement = element?.getElementsByTagName("button")[0];
1313
buttonElement?.setAttribute("aria-expanded", ariaExpanded);
14-
buttonElement?.setAttribute("aria-label", ariaLabel);
1514
};
1615

1716
const DxcPasswordInput = forwardRef<RefType, PasswordInputPropsType>(
@@ -32,6 +31,7 @@ const DxcPasswordInput = forwardRef<RefType, PasswordInputPropsType>(
3231
margin,
3332
size = "medium",
3433
tabIndex = 0,
34+
ariaLabel = "Password input",
3535
},
3636
ref
3737
) => {
@@ -44,12 +44,12 @@ const DxcPasswordInput = forwardRef<RefType, PasswordInputPropsType>(
4444
if (isPasswordVisible) {
4545
setInputType("text", inputRef.current);
4646
if (passwordInput.inputHidePasswordTitle) {
47-
setAriaAttributes("true", passwordInput.inputHidePasswordTitle, inputRef.current);
47+
setAriaAttributes("true", inputRef.current);
4848
}
4949
} else {
5050
setInputType("password", inputRef.current);
5151
if (passwordInput.inputShowPasswordTitle) {
52-
setAriaAttributes("false", passwordInput.inputShowPasswordTitle, inputRef.current);
52+
setAriaAttributes("false", inputRef.current);
5353
}
5454
}
5555
})();
@@ -81,6 +81,7 @@ const DxcPasswordInput = forwardRef<RefType, PasswordInputPropsType>(
8181
autocomplete={autocomplete}
8282
ref={inputRef}
8383
tabIndex={tabIndex}
84+
ariaLabel={ariaLabel}
8485
/>
8586
</PasswordInput>
8687
);

packages/lib/src/password-input/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type Props = {
9292
* Value of the tabindex attribute.
9393
*/
9494
tabIndex?: number;
95+
/**
96+
* Specifies a string to be used as the name for the password input element when no `label` is provided.
97+
*/
98+
ariaLabel?: string;
9599
};
96100

97101
/**

0 commit comments

Comments
 (0)