Skip to content

Commit a0dd252

Browse files
authored
Merge branch 'master' into jialecl-switch-ariaLabel
2 parents 7e2b318 + 1173457 commit a0dd252

File tree

8 files changed

+56
-4
lines changed

8 files changed

+56
-4
lines changed

apps/website/screens/components/select/code/SelectCodePage.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ const sections = [
268268
<td>Reference to the component.</td>
269269
<td>-</td>
270270
</tr>
271+
<tr>
272+
<td>ariaLabel</td>
273+
<td>
274+
<TableCode>string</TableCode>
275+
</td>
276+
<td>
277+
Specifies a string to be used as the name for the select element when no <Code>label</Code> is provided.
278+
</td>
279+
<td>'Select'</td>
280+
</tr>
271281
</tbody>
272282
</DxcTable>
273283
),

apps/website/screens/components/slider/code/SliderCodePage.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ const sections = [
213213
<td>Reference to the component.</td>
214214
<td>-</td>
215215
</tr>
216+
<tr>
217+
<td>ariaLabel</td>
218+
<td>
219+
<TableCode>string</TableCode>
220+
</td>
221+
<td>
222+
Specifies a string to be used as the name for the slider element when no <Code>label</Code> is provided.
223+
</td>
224+
<td>'Slider'</td>
225+
</tr>
216226
</tbody>
217227
</DxcTable>
218228
),

packages/lib/src/select/Select.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,21 @@ describe("Select component tests", () => {
114114
expect(select.getAttribute("aria-labelledby")).toBe(label.id);
115115
expect(select.getAttribute("aria-activedescendant")).toBeNull();
116116
expect(select.getAttribute("aria-invalid")).toBe("false");
117+
expect(select.getAttribute("aria-label")).toBeNull();
117118
await userEvent.click(select);
118119
const list = getByRole("listbox");
119120
expect(select.getAttribute("aria-controls")).toBe(list.id);
120121
expect(list.getAttribute("aria-multiselectable")).toBe("false");
121122
});
122123

124+
test("Renders with correct error aria label", () => {
125+
const { getByRole } = render(
126+
<DxcSelect ariaLabel="Example aria label" placeholder="Example" options={singleOptions} />
127+
);
128+
const select = getByRole("combobox");
129+
expect(select.getAttribute("aria-label")).toBe("Example aria label");
130+
});
131+
123132
test("Single selection: Renders with correct default value", async () => {
124133
const { getByText, getByRole, getAllByRole, queryByRole, container } = render(
125134
<DxcSelect label="test-select-label" name="test" defaultValue="4" options={singleOptions} />

packages/lib/src/select/Select.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const DxcSelect = forwardRef<RefType, SelectPropsType>(
5252
margin,
5353
size = "medium",
5454
tabIndex = 0,
55+
ariaLabel = "Select",
5556
},
5657
ref
5758
): JSX.Element => {
@@ -327,6 +328,7 @@ const DxcSelect = forwardRef<RefType, SelectPropsType>(
327328
aria-invalid={!!error}
328329
aria-errormessage={error ? errorId : undefined}
329330
aria-required={!disabled && !optional}
331+
aria-label={label ? undefined : ariaLabel}
330332
>
331333
{multiple && Array.isArray(selectedOption) && selectedOption.length > 0 && (
332334
<SelectionIndicator>

packages/lib/src/select/types.ts

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

99103
type SingleSelect = CommonProps & {

packages/lib/src/slider/Slider.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ describe("Slider component tests", () => {
2121
const sliderId = getByText("label").getAttribute("id");
2222
expect(getByRole("slider").getAttribute("aria-labelledby")).toBe(sliderId);
2323
expect(getByRole("slider").getAttribute("aria-orientation")).toBe("horizontal");
24+
expect(getByRole("slider").getAttribute("aria-label")).toBeNull();
25+
});
26+
27+
test("Renders with correct error aria label", () => {
28+
const { getByRole } = render(
29+
<DxcSlider ariaLabel="Example aria label" minValue={0} maxValue={100} showLimitsValues />
30+
);
31+
const slider = getByRole("slider");
32+
expect(slider.getAttribute("aria-label")).toBe("Example aria label");
2433
});
2534

2635
test("Slider renders with correct initial value when it is uncontrolled", () => {

packages/lib/src/slider/Slider.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ const DxcSlider = forwardRef<RefType, SliderPropsType>(
248248
labelFormatCallback,
249249
margin,
250250
size = "fillParent",
251+
ariaLabel = "Slider",
251252
},
252253
ref
253254
): JSX.Element => {
@@ -319,9 +320,11 @@ const DxcSlider = forwardRef<RefType, SliderPropsType>(
319320
return (
320321
<ThemeProvider theme={colorsTheme.slider}>
321322
<Container margin={margin} size={size} ref={ref}>
322-
<Label id={labelId} disabled={disabled}>
323-
{label}
324-
</Label>
323+
{label && (
324+
<Label id={labelId} disabled={disabled}>
325+
{label}
326+
</Label>
327+
)}
325328
<HelperText disabled={disabled}>{helperText}</HelperText>
326329
<SliderContainer>
327330
{showLimitsValues && <MinLabelContainer disabled={disabled}>{minLabel}</MinLabelContainer>}
@@ -334,11 +337,12 @@ const DxcSlider = forwardRef<RefType, SliderPropsType>(
334337
max={maxValue}
335338
step={step}
336339
disabled={disabled}
337-
aria-labelledby={labelId}
340+
aria-labelledby={label ? labelId : undefined}
338341
aria-orientation="horizontal"
339342
aria-valuemax={maxValue}
340343
aria-valuemin={minValue}
341344
aria-valuenow={value != null && value >= 0 ? value : innerValue}
345+
aria-label={label ? undefined : ariaLabel}
342346
onChange={handleSliderChange}
343347
onMouseUp={handleSliderOnChangeCommitted}
344348
onMouseDown={handleSliderDragging}

packages/lib/src/slider/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ type Props = {
7373
* Size of the component.
7474
*/
7575
size?: "medium" | "large" | "fillParent";
76+
/**
77+
* Specifies a string to be used as the name for the slider element when no `label` is provided.
78+
*/
79+
ariaLabel?: string;
7680
};
7781

7882
/**

0 commit comments

Comments
 (0)