Skip to content

Commit 379c870

Browse files
committed
fix(react): allow Toggle to disable focus via data-is-focusable attribute
The Toggle component now respects the data-is-focusable attribute, allowing users to disable focus behavior similar to the Checkbox component. This is particularly useful in DetailsList scenarios where arrow key navigation should skip certain interactive elements. Previously, data-is-focusable was hardcoded to true, preventing users from disabling focus. Now it checks toggleNativeProps for the attribute and defaults to true if not provided, maintaining backward compatibility.
1 parent d33ac4d commit 379c870

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

packages/react/src/components/Toggle/Toggle.base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const ToggleBase: React.FunctionComponent<IToggleProps> = React.forwardRe
126126
'aria-label': ariaLabel ? ariaLabel : badAriaLabel,
127127
'aria-labelledby': labelledById,
128128
className: classNames.pill,
129-
'data-is-focusable': true,
129+
'data-is-focusable': toggleNativeProps['data-is-focusable'] ?? true,
130130
'data-ktp-target': true,
131131
disabled,
132132
id,

packages/react/src/components/Toggle/Toggle.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ describe('Toggle', () => {
8787
expect(screen.queryByText('label')).toBeNull();
8888
});
8989

90+
it('renders data-is-focusable true by default', () => {
91+
const { container } = render(<Toggle label="Label" />);
92+
const button = getBySelector(container, 'button') as HTMLButtonElement;
93+
expect(button.getAttribute('data-is-focusable')).toEqual('true');
94+
});
95+
96+
it('respects data-is-focusable false when passed', () => {
97+
const { container } = render(<Toggle label="Label" data-is-focusable={false} />);
98+
const button = getBySelector(container, 'button') as HTMLButtonElement;
99+
expect(button.getAttribute('data-is-focusable')).toEqual('false');
100+
});
101+
90102
it(`doesn't trigger onSubmit when placed inside a form`, () => {
91103
const onSubmit = jest.fn();
92104

0 commit comments

Comments
 (0)