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.
javascript html css wai-aria
add a comment |
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.
javascript html css wai-aria
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
add a comment |
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.
javascript html css wai-aria
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
javascript html css wai-aria
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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