You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
allows user to opt-out of the uncontrolled open state change by passing a boolean as the return of onOpenChange
To opt-out of Escape for example, this is doable:
<DialogonOpenChange={(event,data)=>{if(data.type==="escapeKeyDown"){returnfalse// opting out of modifying the internal open state}}}modalType="alert">{/*...*/}</Dialog>
bsunderhus
changed the title
feat: allows user to opt-out of uncontrolled open changes
feat(react-dialog): allows user to opt-out of uncontrolled open changes
Sep 21, 2023
Default prevention can't be trusted on all use case scenarios, for example on navigation cases the prevention will be required to stop scrolling, and then there's no way you can tell if the prevention means "don't do nothing" or "do something but don't scroll", This problem is present in #29091
So in order to maintain a single way of doing things over the library I believe we shouldn't trust default prevention anywhere.
Also, preventing default on click events might cause some unexpected behaviours on applications that listen/capture event clicks globally
you are proposing a new way to prevent library's behavior that should be consistent
Is it correct?
Correct, it works in current scenario but it has never been documented and it's not an official solution. We don't have an official solution for an opt-out mechanism, at the moment if you want to opt-out you have to control the state (in the majority of v9 components).
I'll convert this back into a draft, as I believe this mechanism should be better discussed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previous Behavior
At the moment if the user wants to prevent
Escapeto close a dialog, controlling the dialog open state is requiredhttps://codesandbox.io/s/sad-star-c7ytcs?file=/example.tsx
New Behavior
onOpenChangeTo opt-out of
Escapefor example, this is doable: