Proposal to Extend useDismiss
Hook with onDismiss
Callback
#2860
Closed
pascalrogalla
started this conversation in
Ideas
Replies: 1 comment
-
The only disadvantage to a dedicated
type OpenChangeReason =
| 'outside-press'
| 'escape-key'
| 'ancestor-scroll'
| 'reference-press'
| 'click'
| 'hover'
| 'focus'
| 'list-navigation'
| 'safe-polygon'; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, the
useDismiss
hook in the floating UI does not support the passing of anonDismiss
callback. As a result, when it's necessary to react to the dismissal of a dialog, developers are required to "abuse" theonOpenChange
function for this purpose. This proposal suggests extending the props of theuseDismiss
hook to include anonDismiss
callback. Additionally, it outlines the advantages that such an extension would offer.Proposal:
The
useDismiss
hook is a vital tool in managing floating UI elements. However, its current implementation lacks support for anonDismiss
callback. This omission necessitates unconventional workarounds, such as repurposing theonOpenChange
function, to handle dismissal events effectively. To address this limitation and enhance the usability of the hook, I propose extending its props to include anonDismiss
callback.Advantages of Extending
useDismiss
withonDismiss
Callback:Clarity and Intent: Adding an explicit
onDismiss
callback clarifies the purpose of the hook and improves code readability. Developers can immediately discern the intended functionality without resorting to unconventional usage patterns.Separation of Concerns: Separating dismissal logic into its dedicated callback promotes cleaner code architecture by adhering to the principle of single responsibility. Developers can isolate dismissal-related actions, enhancing maintainability and facilitating future modifications.
Enhanced Flexibility: Introducing an
onDismiss
callback empowers developers to execute custom actions in response to dismissal events. Whether it involves state updates, API calls, or UI transitions, this flexibility fosters creativity and enables tailored user experiences.Consistency and Compatibility: By aligning the
useDismiss
hook with established patterns and conventions, such as the inclusion of callbacks for common interactions, this extension promotes consistency across codebases. Furthermore, it ensures compatibility with existing frameworks and libraries that rely on similar callback mechanisms.Improved Error Handling: With an
onDismiss
callback, developers gain finer control over error handling and validation during dismissal operations. They can intercept errors, provide informative feedback to users, and gracefully handle exceptional scenarios, thereby enhancing the robustness of their applications.Conclusion:
Extending the
useDismiss
hook with anonDismiss
callback is a pragmatic enhancement that aligns with the principles of clarity, separation of concerns, flexibility, consistency, and error handling. By embracing this proposal, we can streamline development workflows, improve code quality, and empower developers to craft more intuitive and resilient user interfaces. I invite feedback and collaboration from the community to refine and implement this feature, enriching the floating UI experience for all users.Thank you for considering this proposal.
Beta Was this translation helpful? Give feedback.
All reactions