Skip to content

Commit 65983e6

Browse files
wesruvcastastrophegithub-actions[bot]
authored
fix: [pfe-primary-detail] usable in IE11 (#1351) (#1352)
* 1351: Fixed primary-detail so it's usable in IE11 Avoided replacing nav item markup, which was causing bugs and duplicate content in IE11 Added CSS for IE * Removing duplicate code * Update 11ty documentation after latest merge from master * Remove console log * Update changelog and baseline images * Newline in CHANGELOG fix Co-authored-by: [ Cassondra ] <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2cf2f9f commit 65983e6

File tree

8 files changed

+71
-66
lines changed

8 files changed

+71
-66
lines changed

CHANGELOG-1.x.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.5.2 (2021)
2+
3+
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: pfe-primary-detail IE11 rendering fix
4+
15
# 1.5.1 (2021-04-15)
26

37
- [48b3c30](https://github.com/patternfly/patternfly-elements/commit/48b3c305367d41fefbb1b01fb3d9189bf96a85f5) fix: adjust word-count calculation on pfe-readtime

elements/pfe-primary-detail/docs/index.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ tags:
1818
## Overview
1919
A primary-detail layout is an interface that shows a list of items and the corresponding details of the selected item. This component is an implementation of one of the "Primary detail simple list in card" from [Patternfly React](https://www.patternfly.org/v4/demos/primary-detail).
2020

21-
<br><br><br><br>
22-
2321
<pfe-primary-detail>
2422
<h3 slot="details-nav">Section 1: Infrastructure and Management</h3>
2523
<div slot="details">
@@ -64,6 +62,11 @@ A primary-detail layout is an interface that shows a list of items and the corre
6462
<pfe-primary-detail>
6563
:::
6664

65+
::: section
66+
## Accessibility
67+
The provided markup should be semantic so that if the component can't load, the user still has an appropriate experience. Once it upgrades, the appropriate tab interactions and markup for assistive tech is added to the component.
68+
:::
69+
6770
::: section
6871
## Installation
6972
```shell
@@ -176,24 +179,16 @@ npm install @patternfly/pfe-primary-detail
176179
## Slots
177180
For this component to work, there should be an equal number of `details-nav` and `details` slotted elements.
178181

179-
### details-nav
180-
Should be added to each heading, it will build the nav that shows the related content.
181-
182-
### details
183-
Should be added to the content, which should directly follow the heading it relates to.
184-
185-
### details-nav--header
186-
In case content needs to be added at the top of the nav area. Will not be matched up with `details` content.
187-
188-
### details-nav--footer
189-
In case contnet needs to be added at the bottom of the nav. Will not be matched up with `details` content.
182+
- **details-nav**: Added to each heading; builds the navigation that shows the related content.
183+
- **details**: Added to the content, directly following the heading to which it relates.
184+
- **details-nav--header**: In case content needs to be added at the top of the navigation area; this will not be matched up with `details` content.
185+
- **details-nav--footer**: In case content needs to be added at the bottom of the navigation; will not be matched up with `details` content.
190186
:::
191187

192188
::: section
193189
## Attributes
194190

195-
### consistent-height
196-
Makes sure the primary details element doesn't change height when a different `details` item is shown.
191+
- **consistent-height**: Makes sure the primary details element doesn't change height when a different `details` item is shown.
197192
:::
198193

199194
::: section

elements/pfe-primary-detail/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"pfelement": {
55
"className": "PfePrimaryDetail",
66
"elementName": "pfe-primary-detail",
7+
"preview": "pfe-primary-detail.png",
78
"files": {
89
"styles": "./src/pfe-primary-detail.scss",
910
"template": "./src/pfe-primary-detail.html",
36.5 KB
Loading

elements/pfe-primary-detail/src/pfe-primary-detail.js

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const lightDomObserverConfig = {
1010
childList: true
1111
};
1212

13-
// @todo Add keyboard controls for arrows?
14-
// @todo Add functions to open a specific item by index or ID
13+
// @TODO Add keyboard controls for arrows?
14+
// @TODO Add functions to open a specific item by index or ID
1515
class PfePrimaryDetail extends PFElement {
1616
static get tag() {
1717
return "pfe-primary-detail";
@@ -88,6 +88,7 @@ class PfePrimaryDetail extends PFElement {
8888

8989
constructor() {
9090
super(PfePrimaryDetail, { type: PfePrimaryDetail.PfeType });
91+
this.isIE = !!window.MSInputMethodContext && !!document.documentMode;
9192

9293
this._handleHideShow = this._handleHideShow.bind(this);
9394
this._initDetailsNav = this._initDetailsNav.bind(this);
@@ -120,7 +121,10 @@ class PfePrimaryDetail extends PFElement {
120121
this._observer.observe(this, lightDomObserverConfig);
121122

122123
// Set first item as active for initial load
123-
this._handleHideShow({ target: this._slots.detailsNav[0] });
124+
this._handleHideShow({
125+
target: this._slots.detailsNav[0],
126+
pfeInitializing: true
127+
});
124128
}
125129

126130
disconnectedCallback() {
@@ -140,43 +144,30 @@ class PfePrimaryDetail extends PFElement {
140144
*/
141145
_initDetailsNav(detailNavElement, index) {
142146
// Don't re-init anything that's been initialized already
143-
if (detailNavElement.tagName === "BUTTON" && detailNavElement.dataset.index && detailNavElement.id) {
147+
if (detailNavElement.hasAttribute("role") && detailNavElement.dataset.index && detailNavElement.id) {
144148
// Make sure the data-index attribute is up to date in case order has changed
145149
detailNavElement.dataset.index = index;
146150
return;
147151
}
148152

149-
let attr = detailNavElement.attributes;
150-
const toggle = document.createElement("button");
151-
152-
toggle.innerHTML = detailNavElement.innerHTML;
153-
154-
// Copy over attributes from original element that aren't in denyList
155-
[...attr].forEach(detailNavElement => {
156-
if (!denyListAttributes.includes(detailNavElement.name)) {
157-
toggle.setAttribute(detailNavElement.name, detailNavElement.value);
158-
}
159-
});
160-
161153
// Set data-index attribute
162-
toggle.dataset.index = index;
154+
detailNavElement.dataset.index = index;
163155

164156
// If the detailNavElement does not have a ID, set a unique ID
165157
if (!detailNavElement.id) {
166-
toggle.setAttribute(
158+
detailNavElement.setAttribute(
167159
"id",
168160
`pfe-detail-toggle-${Math.random()
169161
.toString(36)
170162
.substr(2, 9)}`
171163
);
172164
}
173165

174-
toggle.setAttribute("role", "tab");
175-
toggle.setAttribute("aria-selected", "false");
166+
detailNavElement.setAttribute("role", "tab");
167+
detailNavElement.setAttribute("aria-selected", "false");
176168

177-
toggle.addEventListener("click", this._handleHideShow);
178-
this._slots.detailsNav[index] = toggle;
179-
detailNavElement.replaceWith(toggle);
169+
detailNavElement.addEventListener("click", this._handleHideShow);
170+
this._slots.detailsNav[index] = detailNavElement;
180171
}
181172

182173
/**
@@ -217,6 +208,7 @@ class PfePrimaryDetail extends PFElement {
217208

218209
// Leave a reliable indicator that this has been initialized so we don't do it again
219210
detail.dataset.processed = true;
211+
detail.hidden = true;
220212
}
221213

222214
/**
@@ -264,13 +256,21 @@ class PfePrimaryDetail extends PFElement {
264256
return;
265257
}
266258

267-
const currentToggle = this._slots.detailsNav.find(
268-
toggle => toggle.hasAttribute("aria-selected") && toggle.getAttribute("aria-selected") === "true"
269-
);
259+
let currentToggle = null;
260+
261+
// Find the active toggle by looking through them all and finding the ones with aria-selected set
262+
for (let index = 0; index < this._slots.detailsNav.length; index++) {
263+
const toggle = this._slots.detailsNav[index];
264+
if (toggle.hasAttribute("aria-selected") && toggle.getAttribute("aria-selected") === "true") {
265+
currentToggle = toggle;
266+
break;
267+
}
268+
}
270269

271270
// Get details elements
272271
const nextDetails = this._slots.details[parseInt(nextToggle.dataset.index)];
273272

273+
274274
if (currentToggle) {
275275
const currentDetails = this._slots.details[parseInt(currentToggle.dataset.index)];
276276

@@ -279,6 +279,7 @@ class PfePrimaryDetail extends PFElement {
279279

280280
// Remove Current Detail's attributes
281281
currentDetails.setAttribute("aria-hidden", "true");
282+
currentDetails.hidden = true;
282283

283284
this.emitEvent(PfePrimaryDetail.events.hiddenTab, {
284285
detail: {
@@ -293,6 +294,7 @@ class PfePrimaryDetail extends PFElement {
293294

294295
// Add active attributes to Next Details
295296
nextDetails.setAttribute("aria-hidden", "false");
297+
nextDetails.hidden = false;
296298

297299
this.emitEvent(PfePrimaryDetail.events.shownTab, {
298300
detail: {
@@ -301,12 +303,14 @@ class PfePrimaryDetail extends PFElement {
301303
}
302304
});
303305

304-
// Set focus to pane
305-
const firstFocusableElement = nextDetails.querySelector(
306-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
307-
);
308-
if (firstFocusableElement) {
309-
firstFocusableElement.focus();
306+
// Set focus to pane if this isn't initialization
307+
if (typeof e.pfeInitializing === "undefined") {
308+
const firstFocusableElement = nextDetails.querySelector(
309+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
310+
);
311+
if (firstFocusableElement) {
312+
firstFocusableElement.focus();
313+
}
310314
}
311315
}
312316
}

elements/pfe-primary-detail/src/pfe-primary-detail.scss

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ $LOCAL-VARIABLES: (
2626
}
2727

2828
:host {
29-
display: grid;
30-
grid-template-columns: pfe-local(GridTemplateColumns);
31-
border: pfe-local(Border);
32-
align-items: stretch;
33-
justify-content: stretch;
29+
display: flex;
30+
@supports (display: grid) {
31+
display: grid;
32+
grid-template-columns: pfe-local(GridTemplateColumns);
33+
border: pfe-local(Border);
34+
align-items: stretch;
35+
justify-content: stretch;
36+
}
3437
}
3538

3639
:host([hidden]) {
@@ -42,6 +45,7 @@ $LOCAL-VARIABLES: (
4245
flex-direction: column;
4346
padding: 9px 0;
4447
border-right: pfe-local(Border);
48+
overflow: hidden;
4549
}
4650

4751
::slotted([slot="details-nav"]) {
@@ -69,10 +73,13 @@ $LOCAL-VARIABLES: (
6973
background: pfe-local(Background, $region: details);
7074

7175
:host([consistent-height]) & {
72-
display: grid;
73-
grid-template: 1fr / 1fr;
74-
justify-items: start;
75-
align-items: start;
76+
display: flex;
77+
@supports (display: grid) {
78+
display: grid;
79+
grid-template: 1fr / 1fr;
80+
justify-items: start;
81+
align-items: start;
82+
}
7683
}
7784
}
7885

elements/pfe-primary-detail/test/pfe-primary-detail_test.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ suite("<pfe-primary-detail>", () => {
124124
"Toggle's role is not set to tab"
125125
);
126126

127-
assert.strictEqual(
128-
toggle.tagName,
129-
'BUTTON',
130-
"Toggle's tag is not button"
131-
);
132-
133127
// Get the details (controlled) element
134128
const controlledElement = document.getElementById(ariaControls);
135129
assert.isNotNull(
@@ -196,7 +190,7 @@ suite("<pfe-primary-detail>", () => {
196190
// Another test should have failed if this was an issue,
197191
// BUT want to make sure that the element with ID is processed and the ID was maintained
198192
assert.isTrue(
199-
detailNavWithId.tagName === 'BUTTON',
193+
detailNavWithId.hasAttribute('data-index'),
200194
"Detail nav appears to be in default state and wasn't processed?"
201195
);
202196

@@ -213,7 +207,7 @@ suite("<pfe-primary-detail>", () => {
213207

214208
flush(() => {
215209
// test dynamically prepended content
216-
const firstNavItem = defaultWrapper.querySelector("button");
210+
const firstNavItem = defaultWrapper.querySelector("[role=tab]");
217211
const firstDetail = defaultWrapper.querySelector("div");
218212
const firstDetailMenuItem = firstDetail.querySelector("li a");
219213
const prependedDetailFirstMenuItem = prependedDetail.querySelector("li a");
@@ -251,7 +245,7 @@ suite("<pfe-primary-detail>", () => {
251245
// test dynamically appened content
252246
activeToggle = defaultWrapper.querySelector('[aria-selected="true"]');
253247

254-
const lastNavItem = defaultWrapper.querySelector("button:last-of-type");
248+
const lastNavItem = defaultWrapper.querySelector("h3:last-of-type");
255249
const lastDetail = defaultWrapper.querySelector("div:last-of-type");
256250
const lastDetailMenuItem = lastDetail.querySelector("li a");
257251
const appendedDetailFirstMenuItem = appendedDetail.querySelector("li a");
@@ -267,7 +261,7 @@ suite("<pfe-primary-detail>", () => {
267261
appendedDetailFirstMenuItem.textContent,
268262
"Dynamically appended detail menu does not equal the text of the last detail menu item"
269263
);
270-
264+
271265
assert.strictEqual(
272266
lastNavItem.dataset.index,
273267
"5",
-53.9 KB
Loading

0 commit comments

Comments
 (0)