Option `allowOutsideClick` should accept a boolean
See original GitHub issueDescription
The prop type for allowOutsideClick
is 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: https://github.com/focus-trap/focus-trap-react/blob/749f02180e8c7cb6c237723419fbb81e739c261a/src/focus-trap-react.js#L31-L47
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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top GitHub Comments
@maraisr I’ll put a PR together later today 👍
Hi @SeanMcP thanks for the issue!
I only recently took over maintainer role, so I’d need to look into this more closely. Ie, to see why this was a function.
At face value I think this wouldn’t be such a bad idea, and probably more performant too 🤷♂️ so yeah, if you wanna raise a PR, I’d be more than happy to take a look! 😃
Thanks again for taking the time for a well-formed issue ❤️