Skip to content

fix(react): allow Toggle to disable focus via data-is-focusable attri...#35846

Open
Br1an67 wants to merge 1 commit intomicrosoft:masterfrom
Br1an67:fix/issue-31935-toggle-focusable-attribute
Open

fix(react): allow Toggle to disable focus via data-is-focusable attri...#35846
Br1an67 wants to merge 1 commit intomicrosoft:masterfrom
Br1an67:fix/issue-31935-toggle-focusable-attribute

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 9, 2026

Fixes #31935

Previous Behavior

The Toggle component had a hardcoded data-is-focusable="true" attribute, which prevented users from disabling focus behavior. This was problematic in scenarios like DetailsList where arrow key navigation should skip certain interactive elements, similar to how Checkbox allows this via inputProps={{ "data-is-focusable": false }}.

New Behavior

The Toggle component now respects the data-is-focusable attribute passed as a prop. Users can now disable focus by passing data-is-focusable={false} to the Toggle component, making it consistent with the Checkbox component's behavior. The default value remains true to maintain backward compatibility.

Usage Example

// Disable focus on Toggle (prevents arrow key navigation in DetailsList)
<Toggle data-is-focusable={false} label="My Toggle" />

// Default behavior (focusable)
<Toggle label="My Toggle" />

Related Issue(s)

Changes

  • Modified Toggle.base.tsx to check toggleNativeProps['data-is-focusable'] and default to true if not provided
  • Added two test cases to verify default behavior and ability to disable focus
  • 2 files changed, 13 insertions(+), 1 deletion(-)

…bute

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.
@Br1an67 Br1an67 requested review from a team and khmakoto as code owners March 9, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TOGGLE doesn't have ability to disable focus via "data-is-focusable". Cannot disable focus in DETAILSLIST like we can with CHECKBOX

1 participant