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: no focus after display horizontal paging page content #330

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
:class="[
'ui-horizontal-paging', { 'ui-horizontal-paging--nested': isNested }
'ui-horizontal-paging', { 'ui-horizontal-paging--nested': isNested },
]"
>
<!-- @slot Use this slot to replace header template. -->
Expand Down Expand Up @@ -37,7 +37,7 @@
name="title"
v-bind="{
headingTitleAttrs,
title: currentTitle
title: currentTitle,
}"
>
<UiHeading v-bind="headingTitleAttrs">
Expand All @@ -49,7 +49,7 @@
<div class="ui-horizontal-paging__wrapper">
<div
:class="[
'ui-horizontal-paging__section', { 'ui-horizontal-paging__section--is-active': isActive }
'ui-horizontal-paging__section', { 'ui-horizontal-paging__section--is-active': isActive },
]"
>
<!-- @slot Use this slot to replace menu template. -->
Expand Down Expand Up @@ -208,7 +208,7 @@
const handleBackClick = () => {
activeItems.value = activeItems.value.slice(0, -1);
};
const menuItems = computed<MenuItemAttrsProps[]>(() => itemsAsArray.value.map((item) => {

Check failure on line 211 in src/components/organisms/UiHorizontalPaging/UiHorizontalPaging.vue

View workflow job for this annotation

GitHub Actions / vue-tsc

No overload matches this call.
/* eslint-disable @typescript-eslint/no-unused-vars */
const {
title,
Expand All @@ -226,6 +226,7 @@
item,
];
},
tabindex: isActive.value ? '-1' : null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AlanLes I have one TS error; Can you help me and know how to fix it?

Copy link
Contributor

@AlanLes AlanLes Jan 11, 2024

Choose a reason for hiding this comment

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

Hello, sure what's the error? :)
kkk, I'm on it :)

Copy link
Contributor

@AlanLes AlanLes Jan 11, 2024

Choose a reason for hiding this comment

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

It does the job :)

Suggested change
tabindex: isActive.value ? '-1' : null,
tabindex: isActive.value ? '-1' : undefined,

tabindex doesn't seem to accept the null value :)

but I'm not sure if it wouldn't be better to implicitly not set the tabindex property at all... instead of setting it to undefined.
It could be done with this line instead:

Suggested change
tabindex: isActive.value ? '-1' : null,
...(isActive.value ? { tabindex: '-1' } : {}),

...rest,
};
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<template>
<span
ref="el"
class="visual-hidden"
:tabindex="tabindex"
@blur="handleA11YHelperBlur"
/>
<slot v-if="isActive" />
</template>

<script setup lang="ts">
import {
computed,
watch,
ref,
inject,
onBeforeUnmount,
type Ref,
type ComputedRef,
} from 'vue';
import type { HorizontalPangingHandleItems } from '../UiHorizontalPaging.vue';
import { focusElement } from '../../../../utilities/helpers';

export interface HorizontalPangingItemProps {
/**
Expand All @@ -35,6 +43,16 @@ const props = withDefaults(defineProps<HorizontalPangingItemProps>(), {
});
const activeItemName = inject<ComputedRef<string>>('activeItemName', computed(() => ''));
const isActive = computed(() => activeItemName.value === props.name);
const el = ref<HTMLSpanElement | null>(null);
const tabindex = ref(0);
watch(isActive, (value) => {
tabindex.value = 0;
if (!value) return;
focusElement(el.value);
});
const handleA11YHelperBlur = () => {
tabindex.value = -1;
};
const item = computed(() => ({
label: props.label,
title: props.title,
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/helpers/focus-element/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/prefer-default-export */
export const focusElement = (el: HTMLElement, focusVisible = false): Promise<void> => {
export const focusElement = (el: HTMLElement | null, focusVisible = false): Promise<void> => {
if (el) {
if (focusVisible) {
document.body.classList.remove('focus-hidden');
Expand Down
Loading