As someone not well-versed in JavaScript, I haven't come across the syntax (click)="expandItem()"
or attr.aria-expanded="isCollapsed"
before. I am more familiar with onclick="expandeItem()"
and aria-expanded="false"
. Despite this, I will set aside that aspect for now.
Initially, it is important to note that your <div>
lacks semantic meaning, requiring various ARIA attributes to rectify this issue. However, before delving into this, it is prudent to consider the "First Rule of ARIA Use", which advises against unnecessary use of ARIA and encourages using native HTML elements whenever possible.
Without further context on your specific situation, I suggest contemplating substituting the <div>
with an actual <button>
, especially if you are dealing with a "disclosure widget".
If employing a real <button>
is not feasible, then your <div>
should include:
tabindex="0"
(enabling keyboard focus)
- a click handler (for mouse users)
- a keyboard handler (to allow keyboard users to interact using space and enter)
- a
role="button"
to convey the appropriate semantics for screen reader users
- (Presuming your
<div>
includes a label)
Additionally, address the aria-expanded
concern by toggling its value within the button's onclick event. Since this attribute represents a "state" rather than a "property", modifying its value will automatically be announced by screen readers.