-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keyboard nav for extensions main screen (#13176)
* working on focus trap composable * working on slide in panel refactor * add change so that we dont have a change on the component diff * fix slidein extension details panel key nav * fine tune cluster badge trigger btn * finish work on extensions page * fix lint errors * address pr comments * fix problems of propagation * update return focus for some modals in the extensions main screen * remove dead code + fix focus selector return for add extensions repo and developer install modals
- Loading branch information
Showing
22 changed files
with
440 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* focusTrap is a composable based on the "focus-trap" package that allows us to implement focus traps | ||
* on components for keyboard navigation is a safe and reusable way | ||
*/ | ||
import { watch, nextTick, onMounted, onBeforeUnmount } from 'vue'; | ||
import { createFocusTrap, FocusTrap } from 'focus-trap'; | ||
|
||
export function getFirstFocusableElement(element:any = document):any { | ||
const focusableElements = element.querySelectorAll( | ||
'a, button, input, textarea, select, details,[tabindex]:not([tabindex="-1"])' | ||
); | ||
const filteredFocusableElements:any = []; | ||
|
||
focusableElements.forEach((el:any) => { | ||
if (!el.hasAttribute('disabled')) { | ||
filteredFocusableElements.push(el); | ||
} | ||
}); | ||
|
||
return filteredFocusableElements.length ? filteredFocusableElements[0] : document.body; | ||
} | ||
|
||
export const DEFAULT_FOCUS_TRAP_OPTS = { | ||
escapeDeactivates: true, | ||
allowOutsideClick: true | ||
}; | ||
|
||
export function useBasicSetupFocusTrap(focusElement: string | HTMLElement, opts:any = DEFAULT_FOCUS_TRAP_OPTS) { | ||
let focusTrapInstance: FocusTrap; | ||
let focusEl; | ||
|
||
onMounted(() => { | ||
focusEl = typeof focusElement === 'string' ? document.querySelector(focusElement) as HTMLElement : focusElement; | ||
|
||
focusTrapInstance = createFocusTrap(focusEl, opts); | ||
|
||
nextTick(() => { | ||
focusTrapInstance.activate(); | ||
}); | ||
}); | ||
|
||
onBeforeUnmount(() => { | ||
if (Object.keys(focusTrapInstance).length) { | ||
focusTrapInstance.deactivate(); | ||
} | ||
}); | ||
} | ||
|
||
export function useWatcherBasedSetupFocusTrapWithDestroyIncluded(watchVar:any, focusElement: string | HTMLElement, opts:any = DEFAULT_FOCUS_TRAP_OPTS) { | ||
let focusTrapInstance: FocusTrap; | ||
let focusEl; | ||
|
||
watch(watchVar, (neu) => { | ||
if (neu) { | ||
nextTick(() => { | ||
focusEl = typeof focusElement === 'string' ? document.querySelector(focusElement) as HTMLElement : focusElement; | ||
|
||
focusTrapInstance = createFocusTrap(focusEl, opts); | ||
|
||
nextTick(() => { | ||
focusTrapInstance.activate(); | ||
}); | ||
}); | ||
} else if (!neu && Object.keys(focusTrapInstance).length) { | ||
focusTrapInstance.deactivate(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.