Skip to content

Commit

Permalink
fix(frontend): フォーカスの挙動を修正 (#14158)
Browse files Browse the repository at this point in the history
* fix(frontend): 直前のパターンを記録するように

* fix(frontend): フォーカス/タブ移動に関する挙動を調整 (#226)

Cherry-pick commit e8c0306

Co-authored-by: taiyme <[email protected]>

* focusのデザイン修正

* move scripts

* Modalにfocus trapを追加

* 記録するホットキーはレートリミット式にする

* escキーのハンドリングをMkModalに統一

* fix

* enterで子メニューを開けるように

* lint

* fix focus trap

* improve switch accessibility

* 一部のmodalのフォーカストラップが外れない問題を修正

* fix

* fix

* Revert "記録するホットキーはレートリミット式にする"

This reverts commit 40a7509.

* Revert "fix(frontend): 直前のパターンを記録するように"

This reverts commit 5372b25.

* Revert "Revert "fix(frontend): 直前のパターンを記録するように""

This reverts commit a9bb52e.

* Revert "Revert "記録するホットキーはレートリミット式にする""

This reverts commit bdac342.

* 試験的にCypressでのFocustrapを無効化

* fix

* fix focus-trap

* Update Changelog

* ✌️

* fix focustrap invocation logic

* スクロールがsticky headerを考慮するように

* 🎨

* スタイルの微調整

* 🎨

* remove deprecated key aliases

* focusElementが足りなかったので修正

* preview系にfocus時スタイルが足りなかったので修正

* `returnFocusElement` -> `returnFocusTo`

* lint

* Update packages/frontend/src/components/MkModalWindow.vue

* Apply suggestions from code review

Co-authored-by: taiy <[email protected]>

* keydownイベントをまとめる

* use correct pesudo-element selector

* fix

* rename

---------

Co-authored-by: taiyme <[email protected]>
Co-authored-by: syuilo <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2024
1 parent 121af77 commit 385969e
Show file tree
Hide file tree
Showing 61 changed files with 920 additions and 379 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
### Client
- Enhance: 内蔵APIドキュメントのデザイン・パフォーマンスを改善
- Enhance: 非ログイン時のハイライトTLのデザインを改善
- Enhance: フロントエンドのアクセシビリティ改善
(Based on https://github.com/taiyme/misskey/pull/226)
- Fix: `/about#federation` ページなどで各インスタンスのチャートが表示されなくなっていた問題を修正
- Fix: ユーザーページの追加情報のラベルを投稿者のサーバーの絵文字で表示する (#13968)
- Fix: リバーシの対局を正しく共有できないことがある問題を修正
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkAchievements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ onMounted(() => {
background: linear-gradient(0deg, #ffee20, #eb7018);
}

&:before {
&::before {
content: "";
display: block;
position: absolute;
Expand All @@ -173,7 +173,7 @@ onMounted(() => {
background: linear-gradient(0deg, #e1e1e1, #7c7c7c);
}

&:before {
&::before {
content: "";
display: block;
position: absolute;
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/components/MkButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ function onMousedown(evt: MouseEvent): void {
}

&:focus-visible {
outline: solid 2px var(--focus);
outline-offset: 2px;
}

Expand Down
12 changes: 1 addition & 11 deletions packages/frontend/src/components/MkChannelFollowButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,7 @@ async function onClick() {
}

&:focus-visible {
&:after {
content: "";
pointer-events: none;
position: absolute;
top: -5px;
right: -5px;
bottom: -5px;
left: -5px;
border: 2px solid var(--focus);
border-radius: 32px;
}
outline-offset: 2px;
}

&:hover {
Expand Down
19 changes: 18 additions & 1 deletion packages/frontend/src/components/MkChannelPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div style="position: relative;">
<MkA :to="`/channels/${channel.id}`" class="eftoefju _panel" tabindex="-1" @click="updateLastReadedAt">
<MkA :to="`/channels/${channel.id}`" class="eftoefju _panel" @click="updateLastReadedAt">
<div class="banner" :style="bannerStyle">
<div class="fade"></div>
<div class="name"><i class="ti ti-device-tv"></i> {{ channel.name }}</div>
Expand Down Expand Up @@ -80,13 +80,30 @@ const bannerStyle = computed(() => {
<style lang="scss" scoped>
.eftoefju {
display: block;
position: relative;
overflow: hidden;
width: 100%;

&:hover {
text-decoration: none;
}

&:focus-within {
outline: none;

&::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
pointer-events: none;
box-shadow: inset 0 0 0 2px var(--focus);
}
}

> .banner {
position: relative;
width: 100%;
Expand Down
8 changes: 8 additions & 0 deletions packages/frontend/src/components/MkClipPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const remaining = computed(() => {
.link {
display: block;

&:focus-visible {
outline: none;

.root {
box-shadow: inset 0 0 0 2px var(--focus);
}
}

&:hover {
text-decoration: none;
color: var(--accent);
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:leaveToClass="defaultStore.state.animation ? $style.transition_fade_leaveTo : ''"
>
<div ref="rootEl" :class="$style.root" :style="{ zIndex }" @contextmenu.prevent.stop="() => {}">
<MkMenu :items="items" :align="'left'" @close="$emit('closed')"/>
<MkMenu :items="items" :align="'left'" @close="emit('closed')"/>
</div>
</Transition>
</template>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkCwButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ function toggle() {
.label {
margin-left: 4px;

&:before {
&::before {
content: '(';
}

&:after {
&::after {
content: ')';
}
}
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/components/MkDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<MkModal ref="modal" :preferType="'dialog'" :zPriority="'high'" @click="done(true)" @closed="emit('closed')">
<MkModal ref="modal" :preferType="'dialog'" :zPriority="'high'" @click="done(true)" @closed="emit('closed')" @esc="cancel()">
<div :class="$style.root">
<div v-if="icon" :class="$style.icon">
<i :class="icon"></i>
Expand Down Expand Up @@ -51,7 +51,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref, shallowRef, computed } from 'vue';
import { ref, shallowRef, computed } from 'vue';
import MkModal from '@/components/MkModal.vue';
import MkButton from '@/components/MkButton.vue';
import MkInput from '@/components/MkInput.vue';
Expand Down Expand Up @@ -156,25 +156,13 @@ function onBgClick() {
if (props.cancelableByBgClick) cancel();
}
*/
function onKeydown(evt: KeyboardEvent) {
if (evt.key === 'Escape') cancel();
}

function onInputKeydown(evt: KeyboardEvent) {
if (evt.key === 'Enter' && okButtonDisabledReason.value === null) {
evt.preventDefault();
evt.stopPropagation();
ok();
}
}

onMounted(() => {
document.addEventListener('keydown', onKeydown);
});

onBeforeUnmount(() => {
document.removeEventListener('keydown', onKeydown);
});
</script>

<style lang="scss" module>
Expand Down
32 changes: 16 additions & 16 deletions packages/frontend/src/components/MkDrive.file.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ function onDragend() {
background: rgba(#000, 0.05);

> .label {
&:before,
&:after {
&::before,
&::after {
background: #0b65a5;
}

&.red {
&:before,
&:after {
&::before,
&::after {
background: #c12113;
}
}
Expand All @@ -133,14 +133,14 @@ function onDragend() {
background: rgba(#000, 0.1);

> .label {
&:before,
&:after {
&::before,
&::after {
background: #0b588c;
}

&.red {
&:before,
&:after {
&::before,
&::after {
background: #ce2212;
}
}
Expand All @@ -159,8 +159,8 @@ function onDragend() {
}

> .label {
&:before,
&:after {
&::before,
&::after {
display: none;
}
}
Expand All @@ -181,32 +181,32 @@ function onDragend() {
left: 0;
pointer-events: none;

&:before,
&:after {
&::before,
&::after {
content: "";
display: block;
position: absolute;
z-index: 1;
background: #0c7ac9;
}

&:before {
&::before {
top: 0;
left: 57px;
width: 28px;
height: 8px;
}

&:after {
&::after {
top: 57px;
left: 0;
width: 8px;
height: 28px;
}

&.red {
&:before,
&:after {
&::before,
&::after {
background: #c12113;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkDrive.folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function onContextmenu(ev: MouseEvent) {
cursor: pointer;

&.draghover {
&:after {
&::after {
content: "";
pointer-events: none;
position: absolute;
Expand Down
33 changes: 25 additions & 8 deletions packages/frontend/src/components/MkEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div class="omfetrab" :class="['s' + size, 'w' + width, 'h' + height, { asDrawer, asWindow }]" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : undefined }">
<input ref="searchEl" :value="q" class="search" data-prevent-emoji-insert :class="{ filled: q != null && q != '' }" :placeholder="i18n.ts.search" type="search" autocapitalize="off" @input="input()" @paste.stop="paste" @keydown.stop.prevent.enter="onEnter">
<input
ref="searchEl"
:value="q"
class="search"
data-prevent-emoji-insert
:class="{ filled: q != null && q != '' }"
:placeholder="i18n.ts.search"
type="search"
autocapitalize="off"
@input="input()"
@paste.stop="paste"
@keydown="onKeydown"
>
<!-- FirefoxのTabフォーカスが想定外の挙動となるためtabindex="-1"を追加 https://github.com/misskey-dev/misskey/issues/10744 -->
<div ref="emojisEl" class="emojis" tabindex="-1">
<section class="result">
Expand Down Expand Up @@ -139,6 +151,7 @@ const props = withDefaults(defineProps<{

const emit = defineEmits<{
(ev: 'chosen', v: string): void;
(ev: 'esc'): void;
}>();

const searchEl = shallowRef<HTMLInputElement>();
Expand Down Expand Up @@ -433,9 +446,18 @@ function paste(event: ClipboardEvent): void {
}
}

function onEnter(ev: KeyboardEvent) {
function onKeydown(ev: KeyboardEvent) {
if (ev.isComposing || ev.key === 'Process' || ev.keyCode === 229) return;
done();
if (ev.key === 'Enter') {
ev.preventDefault();
ev.stopPropagation();
done();
}
if (ev.key === 'Escape') {
ev.preventDefault();
ev.stopPropagation();
emit('esc');
}
}

function done(query?: string): boolean | void {
Expand Down Expand Up @@ -702,11 +724,6 @@ defineExpose({
border-radius: 4px;
font-size: 24px;

&:focus-visible {
outline: solid 2px var(--focus);
z-index: 1;
}

&:hover {
background: rgba(0, 0, 0, 0.05);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/components/MkEmojiPickerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:manualShowing="manualShowing"
:src="src"
@click="modal?.close()"
@esc="modal?.close()"
@opening="opening"
@close="emit('close')"
@closed="emit('closed')"
Expand All @@ -28,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:asDrawer="type === 'drawer'"
:max-height="maxHeight"
@chosen="chosen"
@esc="modal?.close()"
/>
</MkModal>
</template>
Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/src/components/MkFlashPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<MkA :to="`/play/${flash.id}`" class="vhpxefrk _panel" tabindex="-1">
<MkA :to="`/play/${flash.id}`" class="vhpxefrk _panel">
<article>
<header>
<h1 :title="flash.title">{{ flash.title }}</h1>
Expand Down Expand Up @@ -39,6 +39,10 @@ const props = defineProps<{
color: var(--accent);
}

&:focus-visible {
outline-offset: -2px;
}

> article {
padding: 16px;

Expand Down
Loading

0 comments on commit 385969e

Please sign in to comment.