using aria for expandable items











up vote
1
down vote

favorite












I have a expandable div element which is expanded when user clicks.
How can i make it accessible through screen readers.
Below is my code



HTML



    <div class="expandable" (click)="expandItem()" attr.aria-expanded="isCollapsed">
Some content to show on expand
</div>


JS:



expandItem() {
this.isCollapsed = true
}


variable isCollapsed is set to false initially.










share|improve this question
























  • You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
    – misorude
    Nov 19 at 14:08










  • isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
    – Nitesh Rana
    Nov 19 at 14:10










  • Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
    – misorude
    Nov 19 at 14:16










  • I am setting aria attribute sir. It is either true or false.
    – Nitesh Rana
    Nov 19 at 14:24















up vote
1
down vote

favorite












I have a expandable div element which is expanded when user clicks.
How can i make it accessible through screen readers.
Below is my code



HTML



    <div class="expandable" (click)="expandItem()" attr.aria-expanded="isCollapsed">
Some content to show on expand
</div>


JS:



expandItem() {
this.isCollapsed = true
}


variable isCollapsed is set to false initially.










share|improve this question
























  • You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
    – misorude
    Nov 19 at 14:08










  • isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
    – Nitesh Rana
    Nov 19 at 14:10










  • Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
    – misorude
    Nov 19 at 14:16










  • I am setting aria attribute sir. It is either true or false.
    – Nitesh Rana
    Nov 19 at 14:24













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a expandable div element which is expanded when user clicks.
How can i make it accessible through screen readers.
Below is my code



HTML



    <div class="expandable" (click)="expandItem()" attr.aria-expanded="isCollapsed">
Some content to show on expand
</div>


JS:



expandItem() {
this.isCollapsed = true
}


variable isCollapsed is set to false initially.










share|improve this question















I have a expandable div element which is expanded when user clicks.
How can i make it accessible through screen readers.
Below is my code



HTML



    <div class="expandable" (click)="expandItem()" attr.aria-expanded="isCollapsed">
Some content to show on expand
</div>


JS:



expandItem() {
this.isCollapsed = true
}


variable isCollapsed is set to false initially.







javascript html css wai-aria






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 14:22

























asked Nov 19 at 14:05









Nitesh Rana

292216




292216












  • You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
    – misorude
    Nov 19 at 14:08










  • isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
    – Nitesh Rana
    Nov 19 at 14:10










  • Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
    – misorude
    Nov 19 at 14:16










  • I am setting aria attribute sir. It is either true or false.
    – Nitesh Rana
    Nov 19 at 14:24


















  • You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
    – misorude
    Nov 19 at 14:08










  • isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
    – Nitesh Rana
    Nov 19 at 14:10










  • Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
    – misorude
    Nov 19 at 14:16










  • I am setting aria attribute sir. It is either true or false.
    – Nitesh Rana
    Nov 19 at 14:24
















You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
– misorude
Nov 19 at 14:08




You need to toggle the content of the ARIA attribute itself as well. w3.org/WAI/GL/wiki/…
– misorude
Nov 19 at 14:08












isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
– Nitesh Rana
Nov 19 at 14:10




isCollapsed is set to false initially and then is set to true on click. But still screen reader is not responding as if it is open or closed
– Nitesh Rana
Nov 19 at 14:10












Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
– misorude
Nov 19 at 14:16




Are you still talking about your JS variable here? What do you think that has to do with ARIA? No screenreader cares for what variables you might have floating around somewhere. You need to set the attribute on the element to the appropriate value.
– misorude
Nov 19 at 14:16












I am setting aria attribute sir. It is either true or false.
– Nitesh Rana
Nov 19 at 14:24




I am setting aria attribute sir. It is either true or false.
– Nitesh Rana
Nov 19 at 14:24












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I might be showing my javascript ignorance but I haven't seen (click)="expandItem()" or attr.aria-expanded="isCollapsed" before. I have seen onclick="expandeItem()" and aria-expanded="false". But I'll ignore that aspect for now.



First off, your <div> has no semantic meaning so you'll need several ARIA attributes to fix that. But before you do that, consider the "First Rule of ARIA Use", which is essentially to not use ARIA. Use native semantic HTML elements as your first choice if possible.



I'd need more information on your scenario but consider using a real <button> instead of a <div>. It sounds like you might have a "disclosure widget".



If a real <button> is not used, then your <div> will need:





  • tabindex="0" (to allow keyboard focus to move to it)

  • a click handler (for mouse users)

  • a keyboard handler (for keyboard users to use space and enter to select it)

  • a role="button" so a screen reader announces the proper semantics

  • (I'm assuming your <div> has a label)


In addition to that, then you need to resolve your aria-expanded issue. In the onclick of the button (or div), just toggle the value of aria-expanded. Since that attribute is a "state" (instead of a "property"), changing its value will be announced automatically by screen readers.






share|improve this answer





















  • Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
    – Nitesh Rana
    Nov 20 at 13:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376359%2fusing-aria-for-expandable-items%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










I might be showing my javascript ignorance but I haven't seen (click)="expandItem()" or attr.aria-expanded="isCollapsed" before. I have seen onclick="expandeItem()" and aria-expanded="false". But I'll ignore that aspect for now.



First off, your <div> has no semantic meaning so you'll need several ARIA attributes to fix that. But before you do that, consider the "First Rule of ARIA Use", which is essentially to not use ARIA. Use native semantic HTML elements as your first choice if possible.



I'd need more information on your scenario but consider using a real <button> instead of a <div>. It sounds like you might have a "disclosure widget".



If a real <button> is not used, then your <div> will need:





  • tabindex="0" (to allow keyboard focus to move to it)

  • a click handler (for mouse users)

  • a keyboard handler (for keyboard users to use space and enter to select it)

  • a role="button" so a screen reader announces the proper semantics

  • (I'm assuming your <div> has a label)


In addition to that, then you need to resolve your aria-expanded issue. In the onclick of the button (or div), just toggle the value of aria-expanded. Since that attribute is a "state" (instead of a "property"), changing its value will be announced automatically by screen readers.






share|improve this answer





















  • Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
    – Nitesh Rana
    Nov 20 at 13:26















up vote
1
down vote



accepted










I might be showing my javascript ignorance but I haven't seen (click)="expandItem()" or attr.aria-expanded="isCollapsed" before. I have seen onclick="expandeItem()" and aria-expanded="false". But I'll ignore that aspect for now.



First off, your <div> has no semantic meaning so you'll need several ARIA attributes to fix that. But before you do that, consider the "First Rule of ARIA Use", which is essentially to not use ARIA. Use native semantic HTML elements as your first choice if possible.



I'd need more information on your scenario but consider using a real <button> instead of a <div>. It sounds like you might have a "disclosure widget".



If a real <button> is not used, then your <div> will need:





  • tabindex="0" (to allow keyboard focus to move to it)

  • a click handler (for mouse users)

  • a keyboard handler (for keyboard users to use space and enter to select it)

  • a role="button" so a screen reader announces the proper semantics

  • (I'm assuming your <div> has a label)


In addition to that, then you need to resolve your aria-expanded issue. In the onclick of the button (or div), just toggle the value of aria-expanded. Since that attribute is a "state" (instead of a "property"), changing its value will be announced automatically by screen readers.






share|improve this answer





















  • Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
    – Nitesh Rana
    Nov 20 at 13:26













up vote
1
down vote



accepted







up vote
1
down vote



accepted






I might be showing my javascript ignorance but I haven't seen (click)="expandItem()" or attr.aria-expanded="isCollapsed" before. I have seen onclick="expandeItem()" and aria-expanded="false". But I'll ignore that aspect for now.



First off, your <div> has no semantic meaning so you'll need several ARIA attributes to fix that. But before you do that, consider the "First Rule of ARIA Use", which is essentially to not use ARIA. Use native semantic HTML elements as your first choice if possible.



I'd need more information on your scenario but consider using a real <button> instead of a <div>. It sounds like you might have a "disclosure widget".



If a real <button> is not used, then your <div> will need:





  • tabindex="0" (to allow keyboard focus to move to it)

  • a click handler (for mouse users)

  • a keyboard handler (for keyboard users to use space and enter to select it)

  • a role="button" so a screen reader announces the proper semantics

  • (I'm assuming your <div> has a label)


In addition to that, then you need to resolve your aria-expanded issue. In the onclick of the button (or div), just toggle the value of aria-expanded. Since that attribute is a "state" (instead of a "property"), changing its value will be announced automatically by screen readers.






share|improve this answer












I might be showing my javascript ignorance but I haven't seen (click)="expandItem()" or attr.aria-expanded="isCollapsed" before. I have seen onclick="expandeItem()" and aria-expanded="false". But I'll ignore that aspect for now.



First off, your <div> has no semantic meaning so you'll need several ARIA attributes to fix that. But before you do that, consider the "First Rule of ARIA Use", which is essentially to not use ARIA. Use native semantic HTML elements as your first choice if possible.



I'd need more information on your scenario but consider using a real <button> instead of a <div>. It sounds like you might have a "disclosure widget".



If a real <button> is not used, then your <div> will need:





  • tabindex="0" (to allow keyboard focus to move to it)

  • a click handler (for mouse users)

  • a keyboard handler (for keyboard users to use space and enter to select it)

  • a role="button" so a screen reader announces the proper semantics

  • (I'm assuming your <div> has a label)


In addition to that, then you need to resolve your aria-expanded issue. In the onclick of the button (or div), just toggle the value of aria-expanded. Since that attribute is a "state" (instead of a "property"), changing its value will be announced automatically by screen readers.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 2:38









slugolicious

3,86411318




3,86411318












  • Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
    – Nitesh Rana
    Nov 20 at 13:26


















  • Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
    – Nitesh Rana
    Nov 20 at 13:26
















Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
– Nitesh Rana
Nov 20 at 13:26




Thanks. This attr.aria-expand and (click) are in context with angular. Sorry i didn't specify that. But applying role=button solved my issue.
– Nitesh Rana
Nov 20 at 13:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376359%2fusing-aria-for-expandable-items%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]