Skip to content

Commit 169510b

Browse files
committed
feat(Switch): add label prop for accessibility and tooltip support
1 parent 4ccb89b commit 169510b

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

frontend/src/components/Switch/index.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<script setup lang="ts">
22
import { nextTick } from 'vue'
33
4+
import i18n from '@/lang'
5+
46
interface Props {
57
size?: 'default' | 'small'
68
border?: 'default' | 'square'
9+
label?: string
710
disabled?: boolean
811
}
912
@@ -19,6 +22,8 @@ const emits = defineEmits<{
1922
(e: 'change', val: boolean): void
2023
}>()
2124
25+
const { t } = i18n.global
26+
2227
const toggle = () => {
2328
if (props.disabled) return
2429
model.value = !model.value
@@ -29,13 +34,15 @@ const toggle = () => {
2934
<template>
3035
<div
3136
@click="toggle"
37+
v-tips.slow="label"
3238
:class="[size, border, model ? 'on' : 'off', disabled ? 'disabled' : '']"
3339
class="gui-switch relative cursor-pointer h-24 inline-flex items-center rounded-full text-12"
3440
>
3541
<div class="dot absolute h-18 w-18 rounded-full duration-200"></div>
3642

37-
<div v-if="$slots.default" class="slot">
38-
<slot></slot>
43+
<div v-if="$slots.default || label" class="slot line-clamp-1 break-all">
44+
<span v-if="label">{{ t(label) }}</span>
45+
<slot v-if="$slots.default"></slot>
3946
</div>
4047
</div>
4148
</template>

frontend/src/directives/tips.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export default {
1818
}, delay)
1919

2020
el.onmouseenter = (e: MouseEvent) => {
21-
el.dataset.showTips = 'true'
22-
show(e.clientX, e.clientY)
21+
if (binding.value) {
22+
el.dataset.showTips = 'true'
23+
show(e.clientX, e.clientY)
24+
}
2325
}
2426

2527
el.onmouseleave = () => {

frontend/src/views/HomeView/components/GroupsController.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,12 @@ onActivated(() => {
227227
class="sticky flex gap-8 items-center p-8 rounded-8 backdrop-blur-sm"
228228
style="background-color: var(--card-bg)"
229229
>
230-
<Switch v-model="appSettings.app.kernel.autoClose">
231-
{{ t('home.controller.autoClose') }}
232-
</Switch>
233-
<Switch v-model="appSettings.app.kernel.unAvailable">
234-
{{ t('home.controller.unAvailable') }}
235-
</Switch>
236-
<Switch v-model="appSettings.app.kernel.cardMode">
237-
{{ t('home.controller.cardMode') }}
238-
</Switch>
239-
<Switch v-model="appSettings.app.kernel.sortByDelay">
240-
{{ t('home.controller.sortBy') }}
241-
</Switch>
230+
<Switch v-model="appSettings.app.kernel.autoClose" label="home.controller.autoClose" />
231+
<Switch v-model="appSettings.app.kernel.unAvailable" label="home.controller.unAvailable" />
232+
<Switch v-model="appSettings.app.kernel.cardMode" label="home.controller.cardMode" />
233+
<Switch v-model="appSettings.app.kernel.sortByDelay" label="home.controller.sortBy" />
242234
<Button @click="toggleMoreSettings" type="primary" size="small"> ... </Button>
243-
<div class="ml-auto">
235+
<div class="ml-auto flex items-center">
244236
<Button @click="expandAll" v-tips="'home.overview.expandAll'" type="text" icon="expand" />
245237
<Button
246238
@click="collapseAll"

0 commit comments

Comments
 (0)