DEV Community

Discussion on: An Accessible Dark Mode Toggle in React

 
grahamthedev profile image
GrahamTheDev • Edited

Thought you replied to this but it seems to have disappeared?

Anyway, I will just say the door is open if you do need anything, but I won't write an essay next time as we seem to have gotten off on the wrong foot because of it! ๐Ÿคฃ

Followed you on Twitter so I don't miss the next article! โค

Thread Thread
 
abbeyperini profile image
Abbey Perini

Hey InHu,

Yeah, I wrote up why I still disagreed with many of your points but was advised that since it was factual and didn't match your tone, it seemed rude and I don't want to be rude.

For instance, my toggle does take into account user color mode preference using JavaScript instead of CSS - that's the part I refactored in this blog. However, I will take a look to see if the media query would add functionality.

I've incorporated the feedback I do agree with in the blog update yesterday or in the description of the Github issue I'll get to in the future.

Ultimately, I do still want to caution you against giving feedback this in-depth and pushing developers to be 100% perfect/WCAG AAA compliant without asking first. It's possible it might discourage people because perfect is often the enemy of good. Not to mention these issues often have more than one right answer. However, no one can say trying to make the internet more accessible one component at a time is a bad thing. ๐Ÿ™‚

Thread Thread
 
grahamthedev profile image
GrahamTheDev • Edited

Right, now we are on the same page there is one thing I will say then, don't worry about your responses to me appearing rude. I was more bothered about offending you so now we both agree that we aren't offended it is all good and I will certainly not be bothered by directness if that was the issue ๐Ÿ˜‹

The disagreement on the toggle colour preference I think is just a misunderstanding then and might need a rephrase on my part!

prefers-color-scheme: light is purely for first time visitors, if their system setting is prefers light your site doesn't take it into account yet.

This is entirely different to storing the preference that they select, which works perfectly.

This really is a minor point, it was purely meant to be a point of interest, it is not a big issue and certainly doesn't need to be addressed right away.

If that is the bit that we are disagreeing on then just ignore this point and do it after everything else you have lined up on the site remediation plan!

That is if you even feel like doing it, it is not essential, just good UX!

As for the offering feedback, we are a million miles apart on that point, most of the people I am friends with on here started because of my essays and this is the first time I have had an even remotely negative response. With that being said your caution has been logged and heard! If I have a similar response in the future then I will take your caution into consideration!

If there were other points you want to discuss fire away, if not then I will wait for your next article and see what you tackle next!

Thread Thread
 
abbeyperini profile image
Abbey Perini

My JS pulls the mode set in their browser's localStorage on load whether or not they've clicked on the toggle and then matches in the toggle and on the page, which I was under the impression would be set by something like that. It'll be interesting to see if I can incorporate the CSS check easily.

Yeah, I just encourage a lot of very new devs to write and a formatted 4 point list is a lot! Plus, even the experts I've heard advise against going for 100% right off the bat because it would be overwhelming, but I understand that this was not solely in the context of me doing a whole overview of my site, just this component. Wasn't meant to be negative, just factual and quick. I have heard the the tone matching message now. ๐Ÿ˜…

I think React's onClick is the equivalent of writing an event handler like click. I think it's <button> that works on Enter and Space and click automatically.

It's not that I don't know the general concepts or want to spend time on things, and I have been practicing since the moment I picked up HTML, but I don't see enough evidence to spend time on user style sheets and am going to lump in making sure the toggle is obvious to cognitively impaired users with my final screenreader tests/that Github issue. Plus, as a developer, I need to spend my limited time on issues that will make the most impact during a big audit fix like this.

I think a label on focus/hover should be sufficient for the extraneous color mode toggle that's not a form and am willing to accept if that makes it just a tad bit less accessible for my pretty design. ๐Ÿ˜ญ

Thread Thread
 
grahamthedev profile image
GrahamTheDev • Edited

I think React's onClick is the equivalent of writing an event handler like click. I think it's that works on Enter and Space and click automatically.

Yeah sorry I made a complete hash of that...trying to explain what I was thinking would be more confusing than me just saying "it is fine as it is, ignore me" so I will just say that! ๐Ÿคฃ

And as for the points I raised, you are right, they are not important now, just add them to the list!

I think the last thing I should perhaps have clarified earlier on to save us both a lot of too and fro is that the current design is accessible to a stage where it is better than 95%+ of dark mode toggle switches out there! It certainly is good enough, it is production ready, it would pass an audit(see "NECESSARY CAVEAT") and in fact it is more than good enough it is great!

The changes I suggested will not affect WCAG in any way or affect an audit either, they are good practices not compliance points. (WCAG is far from all encompassing).

I think a label on focus/hover should be sufficient for the extraneous color mode toggle that's not a form and am willing to accept if that makes it just a tad bit less accessible for my pretty design. ๐Ÿ˜ญ

It certainly is, there is knowing the ideal and working to constraints, it is a fair compromise (I am not militant even if it seemed like it, knowing when you can "cut a corner" and still be accessible is part of the game and what makes accessibility fun!)

NECESSARY CAVEAT - Really prickly auditors might say the lightmode version of the toggle does not have contrast of 3:1 with it's surroundings under SC 1.4.1 Non Text Contrast...if they did say that in a report and given the control design using multiple colours etc. I would call them a **** ****** for being picky, but I can't say it would defo pass without pointing that out!

Thread Thread
 
abbeyperini profile image
Abbey Perini

Ooooh I will check out the color contrast because I am militant about that. ๐Ÿ˜‚ I'm not sure any of the automatic tools caught it, but I'll have to doublecheck.

Thread Thread
 
grahamthedev profile image
GrahamTheDev

I don't think automated tools would catch it as you are styling the label rather than the control, the tools are pretty dumb when you start using fancy tricks!