-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Informative] Differences from other alternatives #58
Comments
Edited on August 5th 2021 to include @headlessui/react to the comparison. Hello Sandrina! Thank you for the kind words, that’s very sweet. Right, so I am familiar with the two libraries you mentioned (and some others). I would say the major difference is that they ultimately belong to an encompassing framework ( I’m going to assume you are in fact not using File sizeLet’s start by talking about file size. Here is the information gathered from bundlephobia:
If you ask me, 9Kb for a dialog script is too much. The composition of the After that we have 30% in 2 focus trap packages, which is not too surprising since that is the core of a dialog. Still, 2.9Kb is a lot in my opinion—that’s almost the entire size of On Since there is no way to get only the dialog from Focus trapTrapping the focus within the dialog is probably what’s hardest in building a dialog library. The basics are very easy to cover, but if you want to cover every single case, it takes a lot of effort. And that’s because getting all focusable elements is way harder than it should be. a11y-dialog uses focusable-selectors, a micro-package of my own, which exposes a CSS selector aiming at querying all the focusable elements. Unfortunately, it is not possible with CSS only, because of certains cases outlined in the documentation of another package attempting to do this more reliable, focus-trap/tabbable. Looking at how focus-lock (the library used by Looking at FocusScope (the component used by The way ImplementationWhen it comes to making anything but the dialog itself “inert” (as in, non discoverable/focusable), you have 2 big methods:
As far as I know, the first method was there first, before the
All that being said, if support with old assistive technologies is of any concern for you, you might want to stick to an implementation that switches the Other featuresAlert dialogsIt seems that all libraries but EventsThey also all provide some sort of event system to react to the dialog being open or closed, which is sometimes necessary to buid more complex interfaces. Nested dialogsI didn’t really dig for nested dialogs’ support since it’s a pretty fishy design pattern anyway, but this is supported by FlexibilityAll libraries provide decent flexibility overall: MiscellaneousAnother thing I noticed is that License & support
All that being said, a dialog is a dialog. Once it’s up and running, it should be able to stand the test of time. The accessibility/browser landscape doesn’t move so fast that our current implementations will become obsolete a year down the line. Heck, years old implementations are still totally great to this day because nothing really changed that much. ConclusionFirst off: any of these 4 libraries will be great. They are all solving the main problem: creating accessible dialogs. So you can’t really go wrong. I’m not a fan of the absence of sub-packages for I will keep using Ultimately, it’s going to depend what you value the most. If you want to do fancy things and want a lot of flexibility, If you want something lightweight and simple, const MyDialogComponent = props => {
const container = React.useRef()
React.useEffect(() => {
const instance = new A11yDialog(container.current)
return () => {
if (instance) instance.destroy()
}
}, [])
return ReactDOM.createPortal(
<div
ref={container}
id={props.id}
aria-labelledby={props.id + '-title'}
aria-hidden='true'
>
<div data-a11y-dialog-hide></div>
<div role='document'>
<h1 id={props.id + '-title'}>{props.title}</h1>
{props.children}
<button type='button' data-a11y-dialog-hide>
Close
</button>
</div>
</div>,
document.body
)
} That was a longer answer than I anticipated. I hope this helps anyway! 💖 |
Holy moly, this was an incredible answer, thank you so much for the effort in doing this analysis! I can assure you that I'll come back to this page many more times when thinking about modals ^.^ |
incredible discussion. thank you! i'm coming from for you fantastic smashing article... would you mind adding a note on this library in your comparison. sincerely, many thanks. really helpful!! |
@dommyboy what smashing article are you referring to? I'm curious now :) |
@dommyboy Done. :) |
@KittyGiraudel you rock 🤘🏼🖤 |
Gosh, reading one comment here is better then pretty much any tutorial I've stumbled across (besides core a11y documentation of course), but wow…what an amazingly thorough clarification 💯 🙌 |
Hi @KittyGiraudel and @morkro,
First of all, thank you for creating this accessible dialog, carefully done and documented! Thank you a lot 🙌
I'm considering replacing a custom dialog/modal implementation in my company's projects with one from the open-source community.
Among many options, this one seems the more solid along with two other candidates that I liked very much:
I'm sure you should be aware of these two libraries. Each one has slightly different implementations / APIs (ways of using), but I believe both have the same features, (or maybe not?).
Could you share your thoughts about those packages and how is this one different from them? Perhaps highlight the differences or the pros/cons?
Thank you 😊
The text was updated successfully, but these errors were encountered: