-
Notifications
You must be signed in to change notification settings - Fork 403
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
Use button
instead of a
for closing modals
#446
Comments
button
instead of a
for closing modals
@Atmos4, But we must avoid breaking changes because we are no longer in beta or release-candidate.
Sure, it would be great if you could open a PR. Note, you also need to reset (EDITED) |
@lucaslarroche Out of curiosity, how much does bundle size matter to this project? If it is important, then I might just go with the first solution I described. It should be doable with I edited the codepen to reflect what I described above, and simplify the CSS to work with |
Semantically valid is more important than the bundle size.
Agreed (EDITED) |
PR is ready, see #448 |
@Atmos4, I edited my comments about targeting So you were right, |
@lucaslarroche it is! Check out the MDN article and this codepen. The original codepen I posted above was also containing this solution. |
Great. I missed it when researching yesterday.
Yes. That's why I suggested at some point to target |
@lucaslarroche The problem with using <dialog>
<article>
<!-- Modal content -->
<footer>
<form>
<button formmethod=dialog>Cancel</button> <!-- this button should look normal! -->
</form>
</footer>
</article>
</dialog> By the way, is there a reason to have some part of the icon specific code coupled to the header? It could be interesting to allow usage of that icon anywhere inside the article, for example like this: <dialog id=modal1>
<article>
<button rel=prev onclick="modal1.close()"></button> <!-- currently doesn't float:right -->
<!-- Modal content -->
</article>
</dialog> I can create an issue/PR to decouple the code if you are interested. Maybe there are valid reasons to have it otherwise though! |
@micchickenburger thank you for your interest in the project. I think you are confused between DOM properties and HTML attributes. Technically you can set any attribute on any HTML element using the As of the Safari issue, it works on my iOS Safari. Can you send a link to a CopePen / Stackblitz? |
Hi @Atmos4, thanks for your reply! I know that arbitrary attributes can be set on elements, but I think this is a bad practice. Therefore, I only use the DOM for programmatically setting attributes. It ensures compliance with the HTML standards. For instance, Setting what appears to be a valid attribute with a valid property (ie |
Good! It sounded like you didn't :) which is fine, you don't need to know everything
Then you are one of a kind: it's actually very common. From the (somewhat standard) use of But this isn't a custom attribute, it's actually an official one that you normally don't use on buttons. Which, in my honest opinion, is also completely fine. It would actually be fine using an anchor tag here since modals are sometimes considered to be valid members of the history, same as actual pages.
You are definitely confused between attribute and property :D it's really not the same thing! Note: I really wonder why you would want to create an |
@Atmos4 Thanks for your reply. I believe I correctly used attribute and property. In the former case I was referring to the HTML element. In the latter case I was referring to the HTMLButtonElement instance in JavaScript, though I did incorrectly call the instantiated object an element. In any case, this is becoming a bit pedantic. Said correctly, To interact with a button element that is not defined in the HTML, one must create it. This can be done in the DOM, as I have, or as an inline HTML string appended to an existing element in HTML. The latter I think is worse because I believe it requires a complete repaint, and must be eval'd. In other words, if the string could be manipulated in any way, ie XSS or in memory, there is no structure or inherent sanitation that would occur. |
Why wouldn't you define it in the HTML? Why would you create it with vanilla JS? So many questions :D
Excellent 👌
You are very stubborn :) for the final time, Side note: the only reason why Anyways, I think we are done with the topic and it's very much down to opinions and knowledge of HTML. Going back to the original question:
|
Describe the issue
The usage of
button
for closing modals makes a lot more sense thana
.Enter
key presses. Buttons respond to bothEnter
andSpace
.href
attribute in order to be accessible. This forces the usage ofhref=#
, which can confuse screen readers and will in fact perform the scroll animation unless theonclick
handler returnsfalse
, which further increases verbosity.Solutions
One solution would be to recommend
button
as a way to close modals, and properly style any button withclass=close
(orrel=prev
even though it is not valid on buttons, and also a non-standard way to describe dialog closing actions).Extending the previous solution for classless pico, we can use
<form method=dialog>
HTML element, which is a non-Javascript solution to closing dialogs. Alternatively if the button is already in a form, we can use<button formmethod=dialog>
.Here is a demo of the extended solution on CodePen.
If you agree on the issue, let me know which solution you like best and I can start working on a PR!
The text was updated successfully, but these errors were encountered: