[TrapFocus] Improve props #25528
Labels
component: FocusTrap
The React component.
new feature
New feature or request
ready to take
Help wanted. Guidance available. There is a high chance the change will be accepted
Summary 💡
() => document
as the default prop value of<TrapFocus getDoc />
.() => true
as the default prop value of<TrapFocus isEnabled />
Motivation 1 🔦
99% of the time*, developers don't need to care about the support of the components for cross documents, e.g iframe. We can make the component simpler to use in these conditions, we can remove the need for a required prop:
https://github.com/mui-org/material-ui/blob/95a8386085a0847b0ba1d4facefae43dde7c076e/packages/material-ui-unstyled/src/Unstable_TrapFocus/Unstable_TrapFocus.d.ts#L9-L13
*1% of usage is probably overestimated considering that RTL is 2% of the cases and we hear a lot more about it. I had a look at popular OS alternatives, it seems that non-support it:
document
option focus-trap/focus-trap#98or is the default:
Proposed solution 1 💡
Motivation 2 🔦
The
isEnabled
prop was introduced to support nested TrapFocus inside portals before #21610. However, It doesn't seem to help us in any way anymore. Worse, in X, we started using TrapFocus, following the demos, without realizing thatisEnabled
needs to be memorized in v4 to function correctly. It leads to this mui/mui-x#1148 (comment).Proposed solution 2 💡
Of course, the demos in the documentation should be updated.
The text was updated successfully, but these errors were encountered: