question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option `allowOutsideClick` should accept a boolean

See original GitHub issue

Description

The prop type for allowOutsideClick is func:

https://github.com/focus-trap/focus-trap-react/blob/749f02180e8c7cb6c237723419fbb81e739c261a/src/focus-trap-react.js#L143

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SeanMcPcommented, Jul 16, 2020

@maraisr I’ll put a PR together later today 👍

1reaction
maraisrcommented, Jul 16, 2020

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 ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dialog: allowOutsideClick, allowEscapeKey · Discussion #691
These options are useful for important dialogs which requires attentive confirmation, ... You can also pass a custom function returning a boolean value, ......
Read more >
Can't set sweetalert options on typescript - Stack Overflow
I'm getting these errors: VSC IntelliSense: 'Argument of type '{ title: string; text: string; type: string; showCancelButton: boolean; ...
Read more >
Boolean - JavaScript - MDN Web Docs
The Boolean object represents a truth value: true or false. ... Warning: You should rarely find yourself using Boolean as a constructor.
Read more >
focus-trap demo - GitHub Pages
This focus trap leverages the escapeDeactivates option as a function rather than a boolean. By default, pressing ESC will deactivate the trap, but...
Read more >
https://unpkg.com/sweetalert2@8.13.5/sweetalert2.d.ts
function isVisible(): boolean; /** * Updates popup options. * See the SweetAlertOptions interface for the list of accepted fields and values. * *...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found