DEV Community

Cover image for Building an Accessible Reveal-Card

Building an Accessible Reveal-Card

Andrew Bone on June 07, 2021

Recently, I found myself craving to make something interesting. So I sat down and scrolled through dribbble to see if there was anything on there t...
Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Unfortunately this pattern won't work (make that doesn't work, I did give it a quick try) properly with a screen reader.

It breaks the ability to open the buttons once a screen reader is involved due to how the click handler behaves.

Also you will never get the "expanded" state announced as it is not valid on a <div>, you could possibly remedy this with role="button" on the <div> but then you have a big issue with nested buttons.

In fact nested interactive elements is something that should be avoided as it can cause havoc with click handlers once a screen reader gets involved.

The other issue is that aria-hidden=true will not hide focusable / interactive elements.

As such when you focus the top panel in a screen reader it still reads out the two buttons (on number 2). You can fix this by adding tabindex="-1" to the buttons when the front section is closed as this removes the items from the focus order (or just use display: none on the buttons until such time as the front cover is moved slightly, which would be preferable).

One last minor point, visible text rather than a title would be great on the buttons for people who can't associate abstract iconography with actions.

How to fix it?

One suggestion on how to fix these issues would be to restructure the HTML so it looks more like an accordion (in the HTML I mean) and then use absolute positioning or a similar technique to position the draggable top section on top of the button holder.

So your button (as you could now make the front card an actual <button>) would open the hidden section which is a sibling of the button.

It might take a little bit of JS trickery to handle touch start and (if you think a mouse slide action is better than a click) the mouse position movement but for screen readers and keyboard only users the behaviour would be much better.

Sorry I can't find any quick fixes with this one ๐Ÿ˜ž but the nested structure is where the issue lies.

Despite all of that I love the design, and obviously it is still very much worthy of a โค and a ๐Ÿฆ„! ๐Ÿ˜

p.s. I gave an answer on Stack Overflow that you could use the principle from that was about a button on top of another button where they appeared to be nested. Not sure if it is useful or not but I thought I would include it just in case.

Preword

Don't nest interactive elements

There is a reason that it isn't valid HTML to nest buttons or hyperlinks, it causes nightmares for knowing which action should be performed on a click (for a start) and for assistive technology this makes things even worse as it can confuse the accessibilityโ€ฆ

Collapse
 
link2twenty profile image
Andrew Bone

I had hoped you'd leave a comment, thank you!

I've update my structure slightly and now the screen reader is reading out the collapsed state correctly. ๐Ÿ˜

Collapse
 
demkantor profile image
demkantor

I only got a chance to view on my phone so couldn't fully test accessibility, I'm no expert either but have worked with accessibility agencies on some projects.
Just some quick notes, you don't want the title attribute and the aria-label at the same time, this can confuse some screen readers. Also I wouldn't suggest an h4 tag, assuming this is to be used on page along with other components it's unlikely that it would line up with an h4, if these arent to be headings I would consider a different tag, comes to mind but maybe there is a better choice yet
Glad to see you taking the initiative to test your skills while making accessibility a focus, not many bother to do much here so great job!

Thread Thread
 
link2twenty profile image
Andrew Bone

I've updated the h4 to another styled span. I can't see anything that says not to use a title though, it appears most screen readers ignore titles by default, and others don't support it at all.

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Not many people hope I come along and write a massive list of things to tackle ๐Ÿ˜œ๐Ÿคฃ

At a glance on my phone it looks way better, if I get chance tomorrow I will have a look on PC!

If you get the pattern right Iโ€™m stealing it as I like the design so it isnโ€™t anything other than selfishness ๐Ÿ˜‰

Collapse
 
wparad profile image
Warren Parad

This is UX so bad it is worthy of being included in one of Google's web apps.

Collapse
 
link2twenty profile image
Andrew Bone

Oh, what's wrong with the UX?

Collapse
 
wparad profile image
Warren Parad
  • A user would never know that there is functionality hidden behind the movement
  • There is no cursor
  • Requires double click to open/close. No one is going to think about that.
  • It isn't clear what the colors means, colors should indicate something
  • The UI display of the text is horrific when the card is opened
  • Cards are frequently bad by design, they often have bad css built in, preventing them being used.
  • Doesn't offer anything of value on mobile, it actually detracts. If I know I need to slide the card, then the slide should be the action, not open more buttons...

That's only the UX, I didn't take a close look at the code, but a quick look reveals the implementation uses events to change classes/css, which is really bad.

Thread Thread
 
link2twenty profile image
Andrew Bone

Ok, I'm not sure I agree with any of those points to be honest ๐Ÿ˜…

  • there is a hint when you mouse over it but if it's included in a site you'd expect the site to explain the expectation to the user
  • there is a grab cursor because you grab the card (again a hint to the user it can be dragged)
  • It does not require a double click you just can use it if you like
  • the colours are arbitrary but the colours I've used are used in many UI and have understood meanings
  • the text is partially hidden as it is no longer the focus, if you wanna read it again feel free to close the panel again
  • cards are just divs with rounded corners and a box shadow, I have no idea how that means it has bad CSS built in
  • it can offer more than one option perhaps this card wouldn't be used if there was only one option (or perhaps it can be used as a warning to make a user think before they perform an action)

Though I do want to ask about why you say using "events to change classes/css" is "really bad"? It's the first time I've heard someone say this is bad.

Thread Thread
 
wparad profile image
Warren Parad • Edited

there is a hint when you mouse over it but if it's included in a site you'd expect the site to explain the expectation to the user

How? If you have to make excuses for your libraries in your UI, you picked the wrong library.

there is a grab cursor because you grab the card (again a hint to the user it can be dragged)

That doesn't show on my screen.

It does not require a double click you just can use it if you like

Your example requires a double click.

the colours are arbitrary but the colours I've used are used in many UI and have understood meanings

They don't have any meaning to a user that is using the card nor the developer selecting which colors they should be. Actually it's worse, the color and display is almost 100% the toast display from bootstrap which indicates the "level" of the message.

the text is partially hidden as it is no longer the focus, if you wanna read it again feel free to close the panel again

That's irrelevant and doesn't make it good UI.

cards are just divs with rounded corners and a box shadow, I have no idea how that means it has bad CSS built in

Cards are frequently discouraged in most frameworks, UX designs, so requiring their use is frequently problematic.

Though I do want to ask about why you say using "events to change classes/css" is "really bad"? It's the first time I've heard someone say this is bad.

Writing JS to do something that css can do natively is an indication of lack of css knowledge. It's also way slower and requires management of unnecessary JS resources which provides another area where it's easy to get it wrong.

Hope that helps.

Thread Thread
 
link2twenty profile image
Andrew Bone

Which browser are you using? The cursor and drag work fine for me on mobile and on desktop in chrome, Firefox and edge?

What am I doing in JS that CSS can do natively?