Skip to content
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

fix: add capability to not auto focus for sidemenu #1012

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/components/DsfrAccordion/DsfrAccordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ onMounted(() => {

watch(isActive, (newValue, oldValue) => {
/*
* @see https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/collapse/collapse.js
* @see https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/collapse/collapse.js
*/
if (newValue !== oldValue) {
doExpand(newValue)
Expand Down
2 changes: 2 additions & 0 deletions src/components/DsfrSideMenu/DsfrSideMenu.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type DsfrSideMenuProps = {
menuItems?: DsfrSideMenuListItemProps[]
headingTitle?: string
titleTag?: string
focusOnExpanding?: boolean
}

export type DsfrSideMenuButtonProps = {
Expand All @@ -26,4 +27,5 @@ export type DsfrSideMenuListProps = {
DsfrSideMenuListItemProps & Partial<DsfrSideMenuListProps & { to?: RouteLocationRaw, text?: string }>
& { menuItems?: (DsfrSideMenuListItemProps & Partial<DsfrSideMenuListProps & { to?: RouteLocationRaw, text?: string }>)[] }
)[]
focusOnExpanding?: boolean
}
3 changes: 2 additions & 1 deletion src/components/DsfrSideMenu/DsfrSideMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ withDefaults(defineProps<DsfrSideMenuProps>(), {
menuItems: () => undefined,
headingTitle: '',
titleTag: 'h3',
focusOnExpanding: true,
})

defineEmits<{ (e: 'toggleExpand', payload: string): void }>()
Expand Down Expand Up @@ -64,7 +65,7 @@ watch(expanded, (newValue, oldValue) => {
'fr-collapse--expanded': cssExpanded, // Need to use a separate data to add/remove the class after a RAF
'fr-collapsing': collapsing,
}"
@transitionend="onTransitionEnd(expanded)"
@transitionend="onTransitionEnd(expanded, focusOnExpanding)"
>
<component
:is="titleTag"
Expand Down
2 changes: 1 addition & 1 deletion src/components/DsfrSideMenu/DsfrSideMenuList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const linkProps = (to: string | RouteLocationRaw | undefined) => {
'fr-collapsing': collapsing,
'fr-collapse--expanded': cssExpanded,
}"
@transitionend="onTransitionEnd(!!expanded)"
@transitionend="onTransitionEnd(!!expanded, focusOnExpanding)"
>
<ul
class="fr-sidemenu__list"
Expand Down
8 changes: 4 additions & 4 deletions src/composables/useCollapsable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const useCollapsable = () => {
}
if (newValue === true) {
// unbound
// @see https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/collapse/collapse.js#L33
// @see https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/collapse/collapse.js
collapse.value.style.setProperty('--collapse-max-height', 'none')
}
// We need to wait for the next RAF to be sure the CSS variable will be set
// DSFR use RAF too https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/api/modules/render/renderer.js#L22
// DSFR use RAF too https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/api/modules/render/renderer.js#L22
window.requestAnimationFrame(() => {
collapsing.value = true
adjust()
Expand All @@ -53,9 +53,9 @@ export const useCollapsable = () => {
* @param {boolean} focusFirstAnchor
* @return void
*/
const onTransitionEnd = (expanded: boolean, focusFirstAnchor: boolean = true): void => {
const onTransitionEnd = (expanded: boolean, autoFocus = true): void => {
collapsing.value = false
if (focusFirstAnchor) {
if (autoFocus) {
collapse.value?.querySelector('a')?.focus()
}
if (collapse.value && expanded === false) {
Expand Down
Loading