I am working on a view more/view less button for comments in a forum app using angular, javascript and css. When the card is collapsed, only the first two lines of text will appear and the rest will be hidden. The problem is that a screen reader will still read the hidden text when the card is collapsed. I am using the NVDA screen reader.
The button should expand the card whenever a user clicks view more and collapse it when the user clicks view less. I have done this by using creating a viewMore Boolean variable and a button that changes the value from true to false and vice-verse on click. There are also two css classes that that make the overflow visible or invisible depending on the value of the Boolean. So the css should look something like this:
.viewLess {
overflow: hidden;
}
.viewMore {
overflow: visible;
height: auto;
}
The button is working fine, but the issue is that a screen reader will still read the hidden overflow text beyond the first two visible lines whenever the card is collapsed. Is there a way to stop a screen reader from reading the hidden overflow text when a card is collapsed, but still have it read the whole card when expanded? Thanks!
Edit: I have added two images showing the basic card and button without styling.