Skip to content

Commit 399f332

Browse files
Pavitra KhatriPavitra Khatri
authored andcommitted
Focus on first visible field in form and in navigable layouts
1 parent 945972f commit 399f332

File tree

21 files changed

+441
-136
lines changed

21 files changed

+441
-136
lines changed

it/content/src/main/content/META-INF/vault/filter.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<filter root="/conf/global/settings/forms" mode="update"/>
1010
<filter root="/conf/global/settings/cloudconfigs/edge-delivery-service-configuration" mode="update"/>
1111
<filter root="/conf/global/settings/cloudconfigs/marketo" mode="update"/>
12+
<filter root="/conf/forms/core-components-it/samples/customfunctionedgedelivery" mode="update"/>
1213
<filter root="/conf/core-components-it" mode="update"/>
1314
<filter root="/conf/wknd" mode="update"/>
1415
<filter root="/conf/datalayerContainer" mode="update"/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
3+
jcr:primaryType="sling:Folder"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
3+
jcr:primaryType="cq:Page">
4+
<jcr:content
5+
cq:lastModified="{Date}2024-04-22T09:56:19.511+05:30"
6+
cq:lastModifiedBy="admin"
7+
cq:template="/libs/core/franklin/shell/components/configuration/page/template"
8+
jcr:primaryType="cq:PageContent"
9+
jcr:title="Edge Delivery Service Configuration"
10+
sling:configPropertyInherit="true"
11+
sling:resourceType="core/franklin/shell/components/configuration/page"
12+
auxiliaryScripts="[https://cdn.jsdelivr.net/gh/adobe/universal-editor-cors@latest/dist/universal-editor-embedded.js,module:scripts/editor-support.js]"
13+
edgeHost="preview"
14+
owner="adobe-rnd"
15+
repo="aem-boilerplate-forms"/>
16+
</jcr:root>

it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/wizard/navigationWithRepeatability/.content.xml

Lines changed: 120 additions & 107 deletions
Large diffs are not rendered by default.

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

Lines changed: 20 additions & 2 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,8 +225,26 @@
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+
229+
// To set the focus on the field when tab expands
230+
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+
}
246+
}
228247
}
229-
}
230248

231249
/**
232250
* Annotates the item and its internals with

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
this.expandItem(item)
9898
}
9999

100-
101100
#collapseAllItems() {
102101
var items = this.getCachedItems();
103102
if (items) {
@@ -245,6 +244,16 @@
245244
return accordionItemDivToBeRepeated;
246245
}
247246

247+
focusOnRepeatableInstances(id) {
248+
const panelId = id.replace(Accordion.idSuffixes.item, "");
249+
const form = this.formContainer.getModel();
250+
const tab = this.getModel().getState().items.find(item => item.type === 'array')?.items?.find(subItem => subItem.id === panelId)
251+
const field = form.getElement(tab?.id);
252+
if (field) {
253+
setTimeout(() => {form.setFocus(field)}, 0);
254+
}
255+
}
256+
248257
handleChildAddition(childView) {
249258
var itemDivToExpand;
250259
this.cacheElements(this._elements.self);
@@ -263,22 +272,44 @@
263272
const newIndex = cachedItems.indexOf(itemDivToExpand);
264273
this.getCachedButtons()[newIndex].classList.remove(this.constructor.cssClasses.button.stepped);
265274
this.getCachedPanels()[newIndex].classList.remove(this.constructor.cssClasses.panel.stepped);
266-
275+
276+
this.focusOnRepeatableInstances(itemDivToExpand.id);
277+
267278
this.#showHideRepeatableButtons(childView.getInstanceManager());
268279
}
269280

270281
handleChildRemoval(removedInstanceView) {
271282
var removedAccordionItemDivId = removedInstanceView.element.id + Accordion.idSuffixes.item;
272283
var removedAccordionItemDiv = this.getItemById(removedAccordionItemDivId);
284+
285+
// Find the previous item before removing the current one
286+
var cachedItems = this.getCachedItems();
287+
var currentIndex = cachedItems.indexOf(removedAccordionItemDiv);
288+
var itemDivToExpand = null;
289+
290+
// If there are items and current item is found
291+
if (cachedItems && cachedItems.length > 0 && currentIndex > -1) {
292+
// If there's a previous item, use it
293+
if (currentIndex > 0) {
294+
itemDivToExpand = cachedItems[currentIndex - 1];
295+
} else {
296+
// If we're removing the first item, use the next one if available
297+
itemDivToExpand = cachedItems[1] || null;
298+
}
299+
}
300+
301+
// Now remove the item
273302
removedAccordionItemDiv.remove();
274303
this.children.splice(this.children.indexOf(removedInstanceView), 1);
275304
this.cacheElements(this._elements.self);
276-
var cachedItems = this.getCachedItems();
277-
if (cachedItems && cachedItems.length > 0) {
278-
var firstItem = cachedItems[0];
279-
this.expandItem(firstItem);
280-
this.collapseAllOtherItems(firstItem.id);
305+
306+
// Expand the target item if found
307+
if (itemDivToExpand) {
308+
this.expandItem(itemDivToExpand);
309+
this.collapseAllOtherItems(itemDivToExpand.id);
310+
this.focusOnRepeatableInstances(itemDivToExpand.id)
281311
}
312+
282313
this.#showHideRepeatableButtons(removedInstanceView.getInstanceManager());
283314
}
284315

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
* @param {Number} index The index of the tab to navigate to
151151
*/
152152
navigate(index) {
153+
if (this._active === index) {
154+
return; // already on this tab
155+
}
153156
this._active = index;
154157
this.addSteppedClass();
155158
this.refreshActive();

0 commit comments

Comments
 (0)