Skip to content

Commit fc89239

Browse files
authored
Merge pull request #1012 from dnum-mi/fix/on-transition-end-focus
fix: add capability to not auto focus for sidemenu
2 parents e02e394 + 45dcd80 commit fc89239

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/components/DsfrAccordion/DsfrAccordion.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ onMounted(() => {
4141
4242
watch(isActive, (newValue, oldValue) => {
4343
/*
44-
* @see https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/collapse/collapse.js
44+
* @see https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/collapse/collapse.js
4545
*/
4646
if (newValue !== oldValue) {
4747
doExpand(newValue)

src/components/DsfrSideMenu/DsfrSideMenu.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type DsfrSideMenuProps = {
1010
menuItems?: DsfrSideMenuListItemProps[]
1111
headingTitle?: string
1212
titleTag?: string
13+
focusOnExpanding?: boolean
1314
}
1415

1516
export type DsfrSideMenuButtonProps = {
@@ -26,4 +27,5 @@ export type DsfrSideMenuListProps = {
2627
DsfrSideMenuListItemProps & Partial<DsfrSideMenuListProps & { to?: RouteLocationRaw, text?: string }>
2728
& { menuItems?: (DsfrSideMenuListItemProps & Partial<DsfrSideMenuListProps & { to?: RouteLocationRaw, text?: string }>)[] }
2829
)[]
30+
focusOnExpanding?: boolean
2931
}

src/components/DsfrSideMenu/DsfrSideMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ withDefaults(defineProps<DsfrSideMenuProps>(), {
1818
menuItems: () => undefined,
1919
headingTitle: '',
2020
titleTag: 'h3',
21+
focusOnExpanding: true,
2122
})
2223
2324
defineEmits<{ (e: 'toggleExpand', payload: string): void }>()
@@ -64,7 +65,7 @@ watch(expanded, (newValue, oldValue) => {
6465
'fr-collapse--expanded': cssExpanded, // Need to use a separate data to add/remove the class after a RAF
6566
'fr-collapsing': collapsing,
6667
}"
67-
@transitionend="onTransitionEnd(expanded)"
68+
@transitionend="onTransitionEnd(expanded, focusOnExpanding)"
6869
>
6970
<component
7071
:is="titleTag"

src/components/DsfrSideMenu/DsfrSideMenuList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const linkProps = (to: string | RouteLocationRaw | undefined) => {
5656
'fr-collapsing': collapsing,
5757
'fr-collapse--expanded': cssExpanded,
5858
}"
59-
@transitionend="onTransitionEnd(!!expanded)"
59+
@transitionend="onTransitionEnd(!!expanded, focusOnExpanding)"
6060
>
6161
<ul
6262
class="fr-sidemenu__list"

src/composables/useCollapsable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export const useCollapsable = () => {
3232
}
3333
if (newValue === true) {
3434
// unbound
35-
// @see https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/collapse/collapse.js#L33
35+
// @see https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/collapse/collapse.js
3636
collapse.value.style.setProperty('--collapse-max-height', 'none')
3737
}
3838
// We need to wait for the next RAF to be sure the CSS variable will be set
39-
// DSFR use RAF too https://github.com/GouvernementFR/dsfr/blob/main/src/core/script/api/modules/render/renderer.js#L22
39+
// DSFR use RAF too https://github.com/GouvernementFR/dsfr/blob/main/src/dsfr/core/script/api/modules/render/renderer.js#L22
4040
window.requestAnimationFrame(() => {
4141
collapsing.value = true
4242
adjust()
@@ -53,9 +53,9 @@ export const useCollapsable = () => {
5353
* @param {boolean} focusFirstAnchor
5454
* @return void
5555
*/
56-
const onTransitionEnd = (expanded: boolean, focusFirstAnchor: boolean = true): void => {
56+
const onTransitionEnd = (expanded: boolean, autoFocus = true): void => {
5757
collapsing.value = false
58-
if (focusFirstAnchor) {
58+
if (autoFocus) {
5959
collapse.value?.querySelector('a')?.focus()
6060
}
6161
if (collapse.value && expanded === false) {

0 commit comments

Comments
 (0)