Add `allowEscape` or another event to handle escape without deactivation
See original GitHub issueHow do you feel about adding allowEscape
to complement escapeDeactivates
, similar to the clickOutsideDeactivates
/allowClickOutside
pair?
I have a use case where I want to navigate to a different page when the user clicks outside or hits escape inside a modal. If the user cancels navigation, the modal should remain open and the focus trap should remain in effect. If allowEscape
existed, I could achieve the behavior with the following options:
{
clickOutsideDeactivates: true,
escapeDeactivates: true,
allowClickOutside: () => {
window.location.href = 'https://www.example.com/';
return true;
},
allowEscape: () => {
window.location.href = 'https://www.example.com/';
return true;
}
}
Another option would be to add onClickOutside
and onEscape
events that are invoked regardless of clickOutsideDeactivates
and escapeDeactivates
properties. The configuration would be:
{
clickOutsideDeactivates: false,
escapeDeactivates: false,
onClickOutside: () => window.location.href = 'https://www.example.com/',
onEscape: () => window.location.href = 'https://www.example.com/'
}
In any case, I’m happy to send a pull request with the implementation if I can get an agreement on what the API should look like.
Edit: Added another example.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top GitHub Comments
This is being published in 6.6.0 right now.
I opened #442 to fix this.