Skip to content

fix(f6navigation): correct activeElement when shadow root doesn't exist #5910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions packages/base/src/features/F6Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,20 @@ class F6Navigation {
const nextIndex = this.groups.indexOf(this.selectedGroup);
let nextElement = null;

if (nextIndex > -1) {
if (nextIndex - 1 < 0) {
nextElement = this.groups[this.groups.length - 1];
Comment on lines -58 to -59
Copy link
Contributor Author

@ZsDeak-SAP ZsDeak-SAP Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 case was the same as the outer if's else branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right.

} else {
// Handle the situation where the first focusable element of two neighbor groups is the same
// For example:
// <ui5-flexible-column-layout>
// <ui5-list>
// <ui5-li>List Item</ui5-li>
// </ui5-list>
// </ui5-flexible-column-layout>
// Here for both FCL & List the firstFoccusableElement is the same (the ui5-li)

const firstFocusable = await getFirstFocusableElement(this.groups[nextIndex - 1], true);
const shouldSkipParent = firstFocusable === await getFirstFocusableElement(this.groups[nextIndex], true);

nextElement = this.groups[shouldSkipParent ? nextIndex - 2 : nextIndex - 1];
}
if (nextIndex > 0) {
// Handle the situation where the first focusable element of two neighbor groups is the same
// For example:
// <ui5-flexible-column-layout>
// <ui5-list>
// <ui5-li>List Item</ui5-li>
// </ui5-list>
// </ui5-flexible-column-layout>
// Here for both FCL & List the firstFoccusableElement is the same (the ui5-li)

const firstFocusable = await getFirstFocusableElement(this.groups[nextIndex - 1], true);
const shouldSkipParent = firstFocusable === await getFirstFocusableElement(this.groups[nextIndex], true);

nextElement = this.groups[shouldSkipParent ? nextIndex - 2 : nextIndex - 1];
} else {
nextElement = this.groups[this.groups.length - 1];
}
Expand All @@ -86,26 +82,27 @@ class F6Navigation {
}

updateGroups() {
this.setSelectedGroup(document.activeElement);
this.setSelectedGroup();
this.groups = getFastNavigationGroups(document.body);
}

setSelectedGroup(element) {
setSelectedGroup(element = document) {
const htmlElement = document.querySelector("html");
element = this.deepActive(element);

while (element && element.getAttribute("data-sap-ui-fastnavgroup") !== "true" && element !== document.querySelector("html")) {
while (element && element.getAttribute("data-sap-ui-fastnavgroup") !== "true" && element !== htmlElement) {
element = element.parentElement ? element.parentNode : element.parentNode.host;
}

this.selectedGroup = element;
}

deepActive(element) {
if (element.shadowRoot) {
return this.deepActive(element.shadowRoot);
deepActive(root) {
if (root.activeElement && root.activeElement.shadowRoot) {
return this.deepActive(root.activeElement.shadowRoot);
}

return element.activeElement;
return root.activeElement;
}

destroy() {
Expand Down