You could create a helper. I mean, in the CSS, if you're using style components, whatever. You could just create a helper and always use that CSS in that element. You could also create a component. I mean, wrap the component that you want to visually hide.
And quickly, let me give you some context of what would happen when you to hide something from the screen readers as well. So, you know, you would use area hidden true. Valid cases would be visually content of your icons meaning, which means here you want to give some meaning to your icons, and still make sure that you want to hide something from the screen readers. So, this is a nice table where I, you know, where I say, you know, often use certain attributes and classes, but make sure how visible and accessible it is. So, it's a quick table that summarizes the stuff.
Let's talk about icon component. I mean, all of us have icons in our project, right? How would you deal with that? So, having an icon component, and here if you see if passed, and icon, and my arrow top right is nothing, but it is some sort of icon, which is like an SVG, and I've also passed a label as a prop. Now, how I would handle this is I would have an icon component, you know, I would check, okay, you know, if there's no label, just return the return the SVG. I mean, return that particular icon with area hidden, which means because we don't require that icon to be known to the screen reader users. So, you know, that this is why we want to use here. And, you know, if there is a label already passed to the icon component, you could just display it and make sure that it is visually hidden, because, you know, you want to you want to give this information only to the screen reader users. And there's also a good example of link icon as well, which you could check later. If you want to know more about working with SVG icons, there's a good article by Florence. So, definitely worth checking.
How would you deal with image component? Same, I mean, you should make sure that, you know, you're passing alt source. And if you want to apply some sort of CSS, do that. Now, here you see what I've done is, you know, if you're passing the alt text, make sure you apply to it. And make sure, you know, sometimes you might just trim, you would like to apply trim to it because it makes sense. And what you also see is I have added a period to it, which means, you know, the screen reader would know that he or she, they need to take a pause here for that particular sentence. And it really helps the screen reader users to understand.
How you and, you know, all of us deal with opening a link in a tab and how you would deal with this. So, I prefer when the screen reader is sort of navigating on your website, whenever they open a link on a new, you know, on your website, there should be a warning that is spoken so that they know that this particular link is opening on the new tab. There should also be a visual warning in the text that the link is opening in the new tab. So any of the two things, quickly, if you take the component, I've done the same thing. You've passed something as a visual hidden class, which will only be visible, which will, you know, visually hidden.
Comments