Skip to content

Commit 943f68e

Browse files
committed
移除 FaDrawer / FaModal 组件内置的 FaScrollArea 组件
1 parent 663c195 commit 943f68e

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

src/layouts/components/Topbar/Toolbar/NavSearch/search.vue

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const searchInput = ref('')
3030
const searchInputRef = useTemplateRef('searchInputRef')
3131
const { focused: searchInputFocused } = useFocus(searchInputRef)
3232
const sourceList = ref<listTypes[]>([])
33-
const actived = ref(-1)
33+
const actived = ref(0)
3434
3535
const searchResultRef = useTemplateRef('searchResultRef')
3636
const searchResultItemRef = useTemplateRef<HTMLElement[]>('searchResultItemRef')
@@ -69,7 +69,7 @@ const resultList = computed(() => {
6969
watch(() => isShow.value, (val) => {
7070
if (val) {
7171
searchInput.value = ''
72-
actived.value = -1
72+
actived.value = 0
7373
// 当搜索显示的时候绑定上、下、回车快捷键,隐藏的时候再解绑。另外当 input 处于 focus 状态时,采用 vue 来绑定键盘事件
7474
hotkeys('up', keyUp)
7575
hotkeys('down', keyDown)
@@ -89,7 +89,7 @@ watch(() => isShow.value, (val) => {
8989
}
9090
})
9191
watch(() => resultList.value, () => {
92-
actived.value = -1
92+
actived.value = 0
9393
handleScroll()
9494
})
9595
@@ -158,15 +158,13 @@ function keyDown() {
158158
}
159159
}
160160
function keyEnter() {
161-
if (actived.value !== -1) {
162-
searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.click()
163-
}
161+
searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.click()
164162
}
165163
function handleScroll() {
166-
if (searchResultRef.value?.areaRef?.ref?.el?.viewportElement) {
167-
const contentDom = searchResultRef.value.areaRef.ref.el.viewportElement
164+
if (searchResultRef.value?.ref?.el?.viewportElement) {
165+
const contentDom = searchResultRef.value.ref.el.viewportElement
168166
let scrollTo = 0
169-
if (actived.value !== -1) {
167+
if (resultList.value.length > 0) {
170168
scrollTo = contentDom.scrollTop
171169
const activedOffsetTop = searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.offsetTop ?? 0
172170
const activedClientHeight = searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.clientHeight ?? 0
@@ -197,7 +195,7 @@ function pageJump(path: listTypes['path'], link: listTypes['link']) {
197195
</script>
198196

199197
<template>
200-
<FaModal ref="searchResultRef" v-model="isShow" border :footer="settingsStore.mode === 'pc'" :closable="false" class="w-full lg-max-w-2xl" content-class="flex flex-col p-0 min-h-auto" header-class="p-0" footer-class="p-0" @opened="searchInputFocused = true">
198+
<FaModal v-model="isShow" border :footer="settingsStore.mode === 'pc'" :closable="false" class="w-full lg-max-w-2xl" content-class="flex flex-col p-0 min-h-auto" header-class="p-0" footer-class="p-0" @opened="searchInputFocused = true">
201199
<template #header>
202200
<div class="h-12 flex flex-shrink-0 items-center">
203201
<div class="h-full w-14 flex-center">
@@ -236,7 +234,7 @@ function pageJump(path: listTypes['path'], link: listTypes['link']) {
236234
</div>
237235
</div>
238236
</template>
239-
<div>
237+
<FaScrollArea ref="searchResultRef">
240238
<template v-if="resultList.length > 0">
241239
<div v-for="(item, index) in resultList" ref="searchResultItemRef" :key="item.path" class="p-4" :data-index="index" @click="pageJump(item.path, item.link)" @mouseover="actived = index">
242240
<a class="flex cursor-pointer items-center border rounded-lg" :class="{ '-mt-4': index !== 0, 'bg-accent': index === actived }">
@@ -268,6 +266,6 @@ function pageJump(path: listTypes['path'], link: listTypes['link']) {
268266
</p>
269267
</div>
270268
</template>
271-
</div>
269+
</FaScrollArea>
272270
</FaModal>
273271
</template>

src/ui/components/FaDrawer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface DrawerProps {
3030
closeOnClickOverlay?: boolean
3131
closeOnPressEscape?: boolean
3232
destroyOnClose?: boolean
33+
openAutoFocus?: boolean
3334
contentClass?: HTMLAttributes['class']
3435
headerClass?: HTMLAttributes['class']
3536
footerClass?: HTMLAttributes['class']

src/ui/components/FaDrawer/index.vue

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const props = withDefaults(
3838
closeOnClickOverlay: true,
3939
closeOnPressEscape: true,
4040
destroyOnClose: true,
41+
openAutoFocus: false,
4142
},
4243
)
4344
@@ -135,6 +136,13 @@ async function onCancel() {
135136
}
136137
}
137138
139+
function handleOpenAutoFocus(e: Event) {
140+
if (!props.openAutoFocus) {
141+
e.preventDefault()
142+
e.stopPropagation()
143+
}
144+
}
145+
138146
function handleFocusOutside(e: Event) {
139147
e.preventDefault()
140148
e.stopPropagation()
@@ -179,7 +187,7 @@ function handleAnimationEnd() {
179187
})"
180188
:side="props.side"
181189
:force-mount="forceMount"
182-
@open-auto-focus="handleFocusOutside"
190+
@open-auto-focus="handleOpenAutoFocus"
183191
@close-auto-focus="handleFocusOutside"
184192
@focus-outside="handleFocusOutside"
185193
@pointer-down-outside="handleClickOutside"
@@ -209,15 +217,11 @@ function handleAnimationEnd() {
209217
<SheetTitle />
210218
<SheetDescription />
211219
</VisuallyHidden>
212-
<div class="m-0 flex-1 of-y-hidden">
213-
<FaScrollArea v-if="!!slots.default" class="h-full">
214-
<div class="p-4">
215-
<slot />
216-
</div>
217-
<div v-show="props.loading" class="absolute inset-0 z-1000 size-full flex-center bg-popover/75">
218-
<FaIcon name="i-line-md:loading-twotone-loop" class="size-10" />
219-
</div>
220-
</FaScrollArea>
220+
<div v-if="!!slots.default" class="relative m-0 flex-1 overflow-y-auto p-4">
221+
<slot />
222+
</div>
223+
<div v-show="props.loading" class="absolute inset-0 z-1000 size-full flex-center bg-popover/75">
224+
<FaIcon name="i-line-md:loading-twotone-loop" class="size-10" />
221225
</div>
222226
<SheetFooter
223227
v-if="footer" :class="cn('p-3 gap-y-2', props.footerClass, {

src/ui/components/FaModal/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface ModalProps {
3434
closeOnClickOverlay?: boolean
3535
closeOnPressEscape?: boolean
3636
destroyOnClose?: boolean
37+
openAutoFocus?: boolean
3738
class?: HTMLAttributes['class']
3839
headerClass?: HTMLAttributes['class']
3940
contentClass?: HTMLAttributes['class']
@@ -147,6 +148,7 @@ export function useFaModal() {
147148
alignCenter: true,
148149
closeOnClickOverlay: false,
149150
destroyOnClose: true,
151+
openAutoFocus: true,
150152
contentClass: 'py-0 min-h-auto',
151153
footerClass: 'p-4',
152154
}
@@ -161,6 +163,7 @@ export function useFaModal() {
161163
alignCenter: true,
162164
closeOnClickOverlay: false,
163165
destroyOnClose: true,
166+
openAutoFocus: true,
164167
contentClass: 'py-0 min-h-auto',
165168
footerClass: 'p-4',
166169
}
@@ -175,6 +178,7 @@ export function useFaModal() {
175178
alignCenter: true,
176179
closeOnClickOverlay: false,
177180
destroyOnClose: true,
181+
openAutoFocus: true,
178182
contentClass: 'py-0 min-h-auto',
179183
footerClass: 'p-4',
180184
}
@@ -189,6 +193,7 @@ export function useFaModal() {
189193
alignCenter: true,
190194
closeOnClickOverlay: false,
191195
destroyOnClose: true,
196+
openAutoFocus: true,
192197
contentClass: 'py-0 min-h-auto',
193198
footerClass: 'p-4',
194199
}
@@ -203,6 +208,7 @@ export function useFaModal() {
203208
showCancelButton: true,
204209
closeOnClickOverlay: false,
205210
destroyOnClose: true,
211+
openAutoFocus: true,
206212
contentClass: 'py-0 min-h-auto',
207213
footerClass: 'p-4',
208214
}

src/ui/components/FaModal/index.vue

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const props = withDefaults(
4242
closeOnClickOverlay: true,
4343
closeOnPressEscape: true,
4444
destroyOnClose: true,
45+
openAutoFocus: false,
4546
},
4647
)
4748
@@ -55,13 +56,8 @@ const slots = defineSlots<{
5556
5657
const dialogContentRef = useTemplateRef('dialogContentRef')
5758
const dialogHeaderRef = ref()
58-
const dialogAreaRef = useTemplateRef('dialogAreaRef')
5959
const dialogRef = ref()
6060
61-
defineExpose({
62-
areaRef: dialogAreaRef,
63-
})
64-
6561
const modalId = shallowRef(props.id ?? useId())
6662
const isOpen = ref(props.modelValue)
6763
const isMaximize = ref(props.maximize)
@@ -174,6 +170,13 @@ async function onCancel() {
174170
}
175171
}
176172
173+
function handleOpenAutoFocus(e: Event) {
174+
if (!props.openAutoFocus) {
175+
e.preventDefault()
176+
e.stopPropagation()
177+
}
178+
}
179+
177180
function handleFocusOutside(e: Event) {
178181
e.preventDefault()
179182
e.stopPropagation()
@@ -222,13 +225,13 @@ function handleAnimationEnd() {
222225
:maximize="isMaximize"
223226
:maximizable="props.maximizable"
224227
:force-mount="forceMount"
225-
:class="cn('left-0 right-0 top-0 md:top-[5vh] flex flex-col p-0 gap-0 mx-auto h-[calc-size(auto,size)] min-h-full md:min-h-auto max-h-full md:max-h-[90vh] translate-x-0 translate-y-0', props.class, {
228+
:class="cn('left-0 right-0 top-0 md:top-[5vh] flex flex-col p-0 gap-0 mx-auto h-[calc-size(auto,size)] min-h-full overflow-hidden md:min-h-auto max-h-full md:max-h-[90vh] translate-x-0 translate-y-0', props.class, {
226229
'md:top-0 size-full max-w-full max-h-full md:max-h-full': isMaximize,
227230
'md:top-1/2 md:-translate-y-1/2!': props.alignCenter,
228231
'duration-0': isDragging,
229232
'hidden': isClosed,
230233
})"
231-
@open-auto-focus="handleFocusOutside"
234+
@open-auto-focus="handleOpenAutoFocus"
232235
@close-auto-focus="handleFocusOutside"
233236
@focus-outside="handleFocusOutside"
234237
@pointer-down-outside="handleClickOutside"
@@ -273,14 +276,12 @@ function handleAnimationEnd() {
273276
<DialogTitle />
274277
<DialogDescription />
275278
</VisuallyHidden>
276-
<FaScrollArea v-if="!!slots.default" ref="dialogAreaRef" class="flex-1">
277-
<div :class="cn('min-h-40 p-4', props.contentClass)">
278-
<slot />
279-
</div>
280-
<div v-show="props.loading" class="absolute inset-0 z-1000 size-full flex-center bg-popover/75">
281-
<FaIcon name="i-line-md:loading-twotone-loop" class="size-10" />
282-
</div>
283-
</FaScrollArea>
279+
<div v-if="!!slots.default" :class="cn('relative flex-1 min-h-40 p-4 overflow-y-auto', props.contentClass)">
280+
<slot />
281+
</div>
282+
<div v-show="props.loading" class="absolute inset-0 z-1000 size-full flex-center bg-popover/75">
283+
<FaIcon name="i-line-md:loading-twotone-loop" class="size-10" />
284+
</div>
284285
<DialogFooter
285286
v-if="footer" :class="cn('p-3 gap-y-2', props.footerClass, {
286287
'md:justify-center': props.center,

0 commit comments

Comments
 (0)