Skip to content

Commit 9ea8f8d

Browse files
johannes-weberJohannes Weber
and
Johannes Weber
authored
chore: Add ariaLabelledBy to InternalDragHandle component (#3431)
Co-authored-by: Johannes Weber <[email protected]>
1 parent 058c6ee commit 9ea8f8d

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

src/internal/components/drag-handle/__tests__/drag-handle-button.test.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ test('assigns aria label and aria description', () => {
4242
expect(document.querySelector(`.${styles.handle}`)).toHaveAccessibleDescription('handle');
4343
});
4444

45+
test('assigns aria-labelledby attribute', () => {
46+
render(
47+
<div>
48+
<div id="label-element">custom label</div>
49+
<DragHandleButton ariaLabelledBy="label-element" />
50+
</div>
51+
);
52+
expect(document.querySelector(`.${styles.handle}`)).toHaveAttribute('aria-labelledby', 'label-element');
53+
expect(document.querySelector(`.${styles.handle}`)).toHaveAccessibleName('custom label');
54+
});
55+
4556
test('has role="button" by default', () => {
4657
render(<DragHandleButton ariaLabel="drag handle" />);
4758

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import React from 'react';
5+
import { render } from '@testing-library/react';
6+
7+
import InternalDragHandle from '../../../../../lib/components/internal/components/drag-handle/index.js';
8+
9+
import styles from '../../../../../lib/components/internal/components/drag-handle/styles.css.js';
10+
11+
test('passes ariaLabelledBy to DragHandleButton', () => {
12+
render(
13+
<div>
14+
<div id="label-element">custom label</div>
15+
<InternalDragHandle ariaLabelledBy="label-element" />
16+
</div>
17+
);
18+
19+
expect(document.querySelector(`.${styles.handle}`)).toHaveAttribute('aria-labelledby', 'label-element');
20+
expect(document.querySelector(`.${styles.handle}`)).toHaveAccessibleName('custom label');
21+
});

src/internal/components/drag-handle/button.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DragHandleButton = forwardRef(
1818
size = 'normal',
1919
className,
2020
ariaLabel,
21+
ariaLabelledBy,
2122
ariaDescribedby,
2223
ariaValue,
2324
disabled,
@@ -62,6 +63,7 @@ const DragHandleButton = forwardRef(
6263
disabled && styles['handle-disabled']
6364
)}
6465
aria-label={ariaLabel}
66+
aria-labelledby={ariaLabelledBy}
6567
aria-describedby={ariaDescribedby}
6668
aria-disabled={disabled}
6769
aria-valuemax={ariaValue?.valueMax}

src/internal/components/drag-handle/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const InternalDragHandle = forwardRef(
1515
variant,
1616
size,
1717
ariaLabel,
18+
ariaLabelledBy,
1819
ariaDescribedby,
1920
tooltipText,
2021
ariaValue,
@@ -41,6 +42,7 @@ const InternalDragHandle = forwardRef(
4142
variant={variant}
4243
size={size}
4344
ariaLabel={ariaLabel}
45+
ariaLabelledBy={ariaLabelledBy}
4446
ariaDescribedby={ariaDescribedby}
4547
ariaValue={ariaValue}
4648
disabled={disabled}

src/internal/components/drag-handle/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface DragHandleProps {
1010
variant?: DragHandleProps.Variant;
1111
size?: DragHandleProps.Size;
1212
ariaLabel?: string;
13+
ariaLabelledBy?: string;
1314
ariaDescribedby?: string;
1415
ariaValue?: DragHandleProps.AriaValue;
1516
disabled?: boolean;

0 commit comments

Comments
 (0)