Skip to content

Commit

Permalink
feat(client): enhance mobile a11y, fold menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 18, 2023
1 parent a3ce12d commit 5da74ea
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
5 changes: 0 additions & 5 deletions packages/client/app/home/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ import Welcome from './welcome.vue'
margin: var(--card-margin);
}
.k-card-body {
margin: var(--card-padding-vertical) 0;
padding: 0 var(--card-padding-horizontal);
}
.k-card.connect {
width: 400px;
max-width: 400px;
Expand Down
37 changes: 35 additions & 2 deletions packages/client/app/layout/header.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="layout-header">
<div class="layout-header" :class="{ 'has-menu': menuKey }">
<div
class="toggle-sidebar-button"
role="button"
Expand All @@ -18,18 +18,31 @@
<div class="right">
<slot name="right"></slot>
</div>
<div class="toggle-menu-button"
v-if="menuKey"
role="button"
tabindex="1"
@click.stop="trigger($event, menuData)"
>
<k-icon name="ellipsis"></k-icon>
</div>
</div>
</template>

<script lang="ts" setup>
import { useRoute } from 'vue-router'
import { useMenu } from '@koishijs/client'
defineProps<{
const props = defineProps<{
isLeftAsideOpen: boolean
isRightAsideOpen: boolean
menuKey?: string
menuData?: any
}>()
const trigger = useMenu(props.menuKey as any)
defineEmits(['update:isLeftAsideOpen', 'update:isRightAsideOpen'])
const route = useRoute()
Expand Down Expand Up @@ -70,10 +83,30 @@ const route = useRoute()
}
}
.toggle-menu-button {
display: none;
height: 100%;
width: var(--header-height);
align-items: center;
justify-content: center;
.k-icon {
height: 1.25rem;
}
}
@media screen and (max-width: 768px) {
.toggle-sidebar-button {
display: block;
}
.toggle-menu-button {
display: flex;
}
.layout-header.has-menu .right {
display: none;
}
}
.layout-header {
Expand Down
6 changes: 5 additions & 1 deletion packages/client/app/layout/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

<div class="main-container">
<div class="aside-mask" @click="isLeftAsideOpen = !isLeftAsideOpen"></div>
<layout-header v-model:isLeftAsideOpen="isLeftAsideOpen" v-model:isRightAsideOpen="isRightAsideOpen">
<layout-header
v-model:isLeftAsideOpen="isLeftAsideOpen"
v-model:isRightAsideOpen="isRightAsideOpen"
:menu-key="typeof menu === 'string' ? menu : null"
:menu-data="menuData">
<template #left>
<slot name="header">{{ route.meta.activity?.name }}</slot>
</template>
Expand Down
16 changes: 7 additions & 9 deletions packages/client/app/theme/menu/menu.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<template>
<transition name="el-zoom-in-top">
<div ref="el" v-show="el" class="k-menu" :style="getStyle()">
<template v-for="item of ctx.internal.menus[id]">
<div class="k-menu-separator" v-if="item.id === '@separator'"></div>
<menu-item v-else v-bind="{ prefix: id, ...item }"></menu-item>
</template>
</div>
</transition>
<div ref="el" class="k-menu" :style="getStyle()">
<template v-for="item of ctx.internal.menus[id]">
<div class="k-menu-separator" v-if="item.id === '@separator'"></div>
<menu-item v-else v-bind="{ prefix: id, ...item }"></menu-item>
</template>
</div>
</template>

<script lang="ts" setup>
Expand All @@ -22,7 +20,7 @@ const ctx = useContext()
const el = ref<HTMLElement>()
const getStyle = () => {
if (!el.value) return {}
if (!el.value) return { visibility: 'hidden' }
const { height, width } = el.value.getBoundingClientRect()
const style: any = {}
if (props.relative.right + width > window.innerWidth) {
Expand Down
6 changes: 5 additions & 1 deletion plugins/config/client/components/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ function allowDrop(source: Node, target: Node, type: 'inner' | 'prev' | 'next')
return target.data.id.startsWith('group:')
}
function handleClick(tree: Tree) {
function handleClick(tree: Tree, target: Node, instance: any, event: MouseEvent) {
model.value = tree.path
// el-tree will stop propagation,
// so we need to manually trigger the event
// so that context menu can be closed.
window.dispatchEvent(new MouseEvent(event.type, event))
}
function handleExpand(data: Tree, target: Node, instance) {
Expand Down

0 comments on commit 5da74ea

Please sign in to comment.