Skip to content

Commit 7e9deeb

Browse files
Fixing Accordion panel cannot collapse when a Text component is the first item. (#1702)
1 parent a252f81 commit 7e9deeb

File tree

2 files changed

+38
-21
lines changed
  • ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/accordion/v1/accordion/clientlibs/commons/js
  • ui.tests/test-module/specs/accordion

2 files changed

+38
-21
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/accordion/v1/accordion/clientlibs/commons/js/common.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
}
8888
}
8989

90-
90+
9191
/**
9292
* Returns all expanded items.
9393
*
@@ -225,26 +225,14 @@
225225
panel.classList.add(this.constructor.cssClasses.panel.expanded);
226226
panel.classList.remove(this.constructor.cssClasses.panel.hidden);
227227
panel.setAttribute("aria-hidden", false);
228-
228+
229229
// To set the focus on the field when tab expands
230230
if (document.activeElement === button) {
231-
const panelId = panel.id.replace(this.constructor.idSuffixes.panel, "");
232-
const form = this.formContainer.getModel();
233-
//Find repeatable tab
234-
let tab = this.getModel().getState().items.find(item => item.type === 'array')?.items?.find(subItem => subItem.id === panelId);
235-
// If not found, try non-repeatable tab
236-
if (!tab) {
237-
tab = this.getModel().getState().items.find(item => item.id === panelId);
238-
}
239-
if (tab && Array.isArray(tab.items) && tab.items.length > 0) {
240-
const field = form.getElement(tab.id);
241-
if (field) {
242-
setTimeout(() => {form.setFocus(field)}, 0);
243-
}
244-
}
245-
}
231+
const focusPanelId = panel.id.replace(this.constructor.idSuffixes.panel, "");
232+
this.focusToFirstVisibleField(focusPanelId);
246233
}
247234
}
235+
}
248236

249237
/**
250238
* Annotates the item and its internals with
@@ -277,7 +265,7 @@
277265
}
278266
};
279267
}
280-
268+
281269

282270
window.Forms = window.Forms || {};
283271
window.Forms.CoreComponentsCommons = window.Forms.CoreComponentsCommons || {};

ui.tests/test-module/specs/accordion/accordion.runtime.cy.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,38 @@ describe("Form with Accordion Container", () => {
112112
cy.get(`#${firstChildComponentItemId}`).should('not.have.attr', 'data-cmp-expanded');
113113
cy.get(`#${firstChildComponentButtonId}`).should('not.have.class', 'cmp-accordion__button--expanded');
114114
cy.get(`#${firstChildComponentPanelId}`).should('not.have.class', 'cmp-accordion__panel--expanded');
115+
116+
cy.get(`#${firstChildComponentButtonId}`).click().then(() => {
117+
cy.get(`#${firstChildComponentButtonId}`).should('have.class', 'cmp-accordion__button--expanded');
118+
cy.get(`#${firstChildComponentButtonId}`).should('have.attr', 'aria-controls', firstChildComponentPanelId);
119+
cy.get(`#${firstChildComponentItemId}`).should('have.attr', 'data-cmp-expanded');
120+
cy.get(`#${firstChildComponentPanelId}`).should('have.class', 'cmp-accordion__panel--expanded');
121+
cy.get(`#${firstChildComponentPanelId}`).should('have.attr', 'aria-labelledby', firstChildComponentButtonId);
122+
123+
cy.get(`#${secondChildComponentItemId}`).should('not.have.attr', 'data-cmp-expanded');
124+
cy.get(`#${secondChildComponentButtonId}`).should('not.have.class', 'cmp-accordion__button--expanded');
125+
cy.get(`#${secondChildComponentPanelId}`).should('not.have.class', 'cmp-accordion__panel--expanded');
126+
127+
cy.get(`#${firstChildComponentButtonId}`).click().then(() => {
128+
cy.get(`#${firstChildComponentButtonId}`).should('not.have.class', 'cmp-accordion__button--expanded');
129+
cy.get(`#${firstChildComponentItemId}`).should('not.have.attr', 'data-cmp-expanded');
130+
cy.get(`#${secondChildComponentItemId}`).should('not.have.attr', 'data-cmp-expanded');
131+
cy.get(`#${secondChildComponentButtonId}`).should('not.have.class', 'cmp-accordion__button--expanded');
132+
cy.get(`#${secondChildComponentPanelId}`).should('not.have.class', 'cmp-accordion__panel--expanded');
133+
134+
cy.get(`#${firstChildComponentButtonId}`).click().then(() => {
135+
cy.get(`#${firstChildComponentButtonId}`).should('have.class', 'cmp-accordion__button--expanded');
136+
cy.get(`#${firstChildComponentButtonId}`).should('have.attr', 'aria-controls', firstChildComponentPanelId);
137+
cy.get(`#${firstChildComponentItemId}`).should('have.attr', 'data-cmp-expanded');
138+
cy.get(`#${firstChildComponentPanelId}`).should('have.class', 'cmp-accordion__panel--expanded');
139+
cy.get(`#${firstChildComponentPanelId}`).should('have.attr', 'aria-labelledby', firstChildComponentButtonId);
140+
});
141+
});
142+
143+
});
115144
});
116-
})
117-
})
145+
});
146+
});
118147

119148
it("should collapse/expand view properly with keyboard", () => {
120149

@@ -276,4 +305,4 @@ describe("Form with Accordion Layout Container with Hidden Children", () => {
276305
cy.get(`#${thirdPanelButtonOfAccordionId}`).should('have.class', 'cmp-accordion__button--expanded');
277306
})
278307
});
279-
});
308+
});

0 commit comments

Comments
 (0)