Skip to content

Commit a62101e

Browse files
authored
fix: pfe-accordion - fixing issues with accessibility when opening and closing panels (#1813) (#1856)
* Fixing issues with accessibility when opening and closing panels. Fixes #1813 * updating changelog
1 parent 0677854 commit a62101e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+54
-34
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Configure node version
8282
uses: actions/setup-node@v1
8383
with:
84-
node-version: ${{ matrix.node }}
84+
node-version: 12.x
8585

8686
# Caching speeds up the npm install step
8787
- name: Cache node modules
@@ -126,7 +126,7 @@ jobs:
126126
- name: Configure node version
127127
uses: actions/setup-node@v1
128128
with:
129-
node-version: ${{ matrix.node }}
129+
node-version: 12.x
130130

131131
# Caching speeds up the npm install step
132132
- name: Access cached node modules
@@ -172,7 +172,7 @@ jobs:
172172
- name: Configure node version
173173
uses: actions/setup-node@v1
174174
with:
175-
node-version: ${{ matrix.node }}
175+
node-version: 12.x
176176

177177
# Set up cross-browser testing on Chromium, WebKit and Firefox with Playwright.
178178
- name: Set up Playwright
@@ -244,7 +244,7 @@ jobs:
244244
- name: Configure node version
245245
uses: actions/setup-node@v1
246246
with:
247-
node-version: ${{ matrix.node }}
247+
node-version: 12.x
248248

249249
# Caching speeds up the npm install step
250250
- name: Access cached node modules

CHANGELOG-1.x.md

Lines changed: 2 additions & 1 deletion

elements/pfe-accordion/src/pfe-accordion-panel.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class PfeAccordionPanel extends PFElement {
3535
title: "Expanded",
3636
type: Boolean,
3737
default: false,
38+
observer: "_expandedChanged"
3839
},
3940
ariaLabelledby: {
4041
type: String,
@@ -49,6 +50,17 @@ class PfeAccordionPanel extends PFElement {
4950

5051
connectedCallback() {
5152
super.connectedCallback();
53+
this._expandedChanged();
54+
}
55+
56+
_expandedChanged() {
57+
if (this.expanded) {
58+
this.removeAttribute("aria-hidden");
59+
this.removeAttribute("tabindex");
60+
} else {
61+
this.setAttribute("aria-hidden", "true");
62+
this.setAttribute("tabindex", "-1");
63+
}
5264
}
5365
}
5466

elements/pfe-accordion/src/pfe-accordion.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class PfeAccordion extends PFElement {
346346
_keydownHandler(evt) {
347347
const currentHeader = evt.target;
348348

349-
if (!this._isHeader(currentHeader)) {
349+
if (!(currentHeader instanceof customElements.get(PfeAccordionHeader.tag))) {
350350
return;
351351
}
352352

@@ -377,10 +377,6 @@ class PfeAccordion extends PFElement {
377377

378378
if (newHeader) {
379379
newHeader.shadowRoot.querySelector("button").focus();
380-
381-
const index = this._getIndex(newHeader);
382-
this.expand(index);
383-
this._setFocus = true;
384380
}
385381
}
386382

elements/pfe-accordion/test/pfe-accordion.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ describe("<pfe-accordion>", () => {
5252
assert.equal(true, header.expanded);
5353
assert.isTrue(panel.hasAttribute('expanded'));
5454
assert.isTrue(panel.expanded);
55+
assert.isTrue(panel.hasAttribute('expanded'));
56+
assert.isTrue(panel.expanded);
5557
});
5658

5759
it('should collapse a panel when an already expanded header is selected', async () => {
@@ -69,6 +71,8 @@ describe("<pfe-accordion>", () => {
6971
assert.equal(false, header.expanded);
7072
assert.isFalse(panel.hasAttribute('expanded'));
7173
assert.isFalse(panel.expanded);
74+
assert.isTrue(panel.getAttribute("aria-hidden") == "true");
75+
assert.isTrue(panel.getAttribute("tabindex") == "-1");
7276
});
7377

7478
it('should randomly generate ids for aria use', async () => {
@@ -101,13 +105,17 @@ describe("<pfe-accordion>", () => {
101105
assert.equal(true, secondHeader.expanded);
102106
assert.isTrue(secondPanel.hasAttribute('expanded'));
103107
assert.isTrue(secondPanel.expanded);
108+
assert.isFalse(secondPanel.hasAttribute("aria-hidden"));
109+
assert.isFalse(secondPanel.hasAttribute("tabindex"));
104110

105111
pfeAccordion.toggle(1);
106112

107113
assert.isTrue(secondHeader.button.getAttribute('aria-expanded') == "false");
108114
assert.equal(false, secondHeader.expanded);
109115
assert.isFalse(secondPanel.hasAttribute('expanded'));
110116
assert.isFalse(secondPanel.expanded);
117+
assert.isTrue(secondPanel.getAttribute("aria-hidden") == "true");
118+
assert.isTrue(secondPanel.getAttribute("tabindex") == "-1");
111119
});
112120

113121
it('should expand a panel when expand is called', async () => {
@@ -121,6 +129,8 @@ describe("<pfe-accordion>", () => {
121129
assert.equal(true, secondHeader.expanded);
122130
assert.isTrue(secondPanel.hasAttribute('expanded'));
123131
assert.isTrue(secondPanel.expanded);
132+
assert.isFalse(secondPanel.hasAttribute("aria-hidden"));
133+
assert.isFalse(secondPanel.hasAttribute("tabindex"));
124134
});
125135

126136
it('should collapse a panel when collapse is called', async () => {
@@ -135,6 +145,8 @@ describe("<pfe-accordion>", () => {
135145
assert.equal(false, secondHeader.expanded);
136146
assert.isFalse(secondPanel.hasAttribute('expanded'));
137147
assert.isFalse(secondPanel.expanded);
148+
assert.isTrue(secondPanel.getAttribute("aria-hidden") == "true");
149+
assert.isTrue(secondPanel.getAttribute("tabindex") == "-1");
138150
});
139151

140152
it('should expand all panels when expandAll is called', async () => {
@@ -152,6 +164,8 @@ describe("<pfe-accordion>", () => {
152164
panels.forEach(panel => {
153165
assert.isTrue(panel.hasAttribute('expanded'));
154166
assert.isTrue(panel.expanded);
167+
assert.isFalse(panel.hasAttribute("aria-hidden"));
168+
assert.isFalse(panel.hasAttribute("tabindex"));
155169
});
156170
});
157171

@@ -171,6 +185,8 @@ describe("<pfe-accordion>", () => {
171185
panels.forEach(panel => {
172186
assert.isFalse(panel.hasAttribute('expanded'));
173187
assert.isFalse(panel.expanded);
188+
assert.isTrue(panel.getAttribute("aria-hidden") == "true");
189+
assert.isTrue(panel.getAttribute("tabindex") == "-1");
174190
});
175191
});
176192

@@ -224,6 +240,8 @@ describe("<pfe-accordion>", () => {
224240
const panel = pfeAccordion._panelForHeader(header);
225241
assert.isTrue(panel.expanded);
226242
assert.isTrue(panel.hasAttribute("expanded"));
243+
assert.isFalse(panel.hasAttribute("aria-hidden"));
244+
assert.isFalse(panel.hasAttribute("tabindex"));
227245
});
228246
});
229247

@@ -402,5 +420,22 @@ describe("<pfe-accordion-panel>", () => {
402420
assert.isTrue(panel.hasAttribute('aria-labelledby'));
403421
assert.equal(panel.getAttribute('role'), 'region');
404422
assert.equal(panel.id, header.getAttribute('aria-controls'));
423+
assert.isFalse(panel.hasAttribute("expanded"));
424+
assert.isTrue(panel.getAttribute("aria-hidden") == "true");
425+
assert.isTrue(panel.getAttribute("tabindex") == "-1");
405426
});
427+
428+
it("should add the proper attributes when a panel's expanded property is toggled", async () => {
429+
const pfeAccordion = await createFixture(testElement);
430+
const panel = pfeAccordion.querySelector("pfe-accordion-panel");
431+
432+
433+
assert.isFalse(panel.hasAttribute("expanded"));
434+
assert.isTrue(panel.getAttribute("aria-hidden") == "true");
435+
assert.isTrue(panel.getAttribute("tabindex") == "-1");
436+
437+
panel.expanded = true;
438+
assert.isFalse(panel.hasAttribute("aria-hidden"));
439+
assert.isFalse(panel.hasAttribute("tabindex"));
440+
})
406441
});

package-lock.json

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-299 KB
Binary file not shown.
-280 KB
Binary file not shown.
-297 KB
Binary file not shown.
333 Bytes

0 commit comments

Comments
 (0)