-
Notifications
You must be signed in to change notification settings - Fork 65
Option allowOutsideClick should accept a boolean #86
Description
Description
The prop type for allowOutsideClick is func:
focus-trap-react/src/focus-trap-react.js
Line 143 in 749f021
| allowOutsideClick: PropTypes.func, |
This is fine (and mimics the focus-trap options), but the name implies that it should also accept a boolean. "allows" is one of those words – like "has", "is", and "will" – that indicates to the user that the value is either true or false.
Expected behavior
Passing true to the allowOutsideClick works as expected.
Actual behavior
A run-time warning is logged and the option is not active.
Possible solution
In this loop:
focus-trap-react/src/focus-trap-react.js
Lines 31 to 47 in 749f021
| for (const optionName in specifiedFocusTrapOptions) { | |
| if ( | |
| !Object.prototype.hasOwnProperty.call( | |
| specifiedFocusTrapOptions, | |
| optionName | |
| ) | |
| ) { | |
| continue; | |
| } | |
| if (optionName === 'returnFocusOnDeactivate') { | |
| continue; | |
| } | |
| tailoredFocusTrapOptions[optionName] = | |
| specifiedFocusTrapOptions[optionName]; | |
| } |
We could add a type check like:
if (optionName === 'allowOutsideClick' && typeof specifiedFocusTrapOptions[optionName] === 'boolean') {
tailoredFocusTrapOptions[optionName] = () => specifiedFocusTrapOptions[optionName]
}Then update the prop types at the bottom to be:
allowOutsideClick: PropTypes.oneOfType([
PropTypes.func,
PropTypes.bool
]),Conclusion
This is a small patch that would make this little feature a little more usable. I'd be happy to contribute and make this addition, but yield to the maintainers for further discussion.