From 943f68e0e03eb034b276bba7bb6bb5dbb0be54a7 Mon Sep 17 00:00:00 2001 From: Hooray <304327508@qq.com> Date: Sun, 9 Nov 2025 19:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20`FaDrawer`=20/=20`FaModal`?= =?UTF-8?q?=20=E7=BB=84=E4=BB=B6=E5=86=85=E7=BD=AE=E7=9A=84=20`FaScrollAre?= =?UTF-8?q?a`=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Topbar/Toolbar/NavSearch/search.vue | 22 ++++++------- src/ui/components/FaDrawer/index.ts | 1 + src/ui/components/FaDrawer/index.vue | 24 ++++++++------ src/ui/components/FaModal/index.ts | 6 ++++ src/ui/components/FaModal/index.vue | 31 ++++++++++--------- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/layouts/components/Topbar/Toolbar/NavSearch/search.vue b/src/layouts/components/Topbar/Toolbar/NavSearch/search.vue index b08255ba..8ce63fd4 100644 --- a/src/layouts/components/Topbar/Toolbar/NavSearch/search.vue +++ b/src/layouts/components/Topbar/Toolbar/NavSearch/search.vue @@ -30,7 +30,7 @@ const searchInput = ref('') const searchInputRef = useTemplateRef('searchInputRef') const { focused: searchInputFocused } = useFocus(searchInputRef) const sourceList = ref([]) -const actived = ref(-1) +const actived = ref(0) const searchResultRef = useTemplateRef('searchResultRef') const searchResultItemRef = useTemplateRef('searchResultItemRef') @@ -69,7 +69,7 @@ const resultList = computed(() => { watch(() => isShow.value, (val) => { if (val) { searchInput.value = '' - actived.value = -1 + actived.value = 0 // 当搜索显示的时候绑定上、下、回车快捷键,隐藏的时候再解绑。另外当 input 处于 focus 状态时,采用 vue 来绑定键盘事件 hotkeys('up', keyUp) hotkeys('down', keyDown) @@ -89,7 +89,7 @@ watch(() => isShow.value, (val) => { } }) watch(() => resultList.value, () => { - actived.value = -1 + actived.value = 0 handleScroll() }) @@ -158,15 +158,13 @@ function keyDown() { } } function keyEnter() { - if (actived.value !== -1) { - searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.click() - } + searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.click() } function handleScroll() { - if (searchResultRef.value?.areaRef?.ref?.el?.viewportElement) { - const contentDom = searchResultRef.value.areaRef.ref.el.viewportElement + if (searchResultRef.value?.ref?.el?.viewportElement) { + const contentDom = searchResultRef.value.ref.el.viewportElement let scrollTo = 0 - if (actived.value !== -1) { + if (resultList.value.length > 0) { scrollTo = contentDom.scrollTop const activedOffsetTop = searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.offsetTop ?? 0 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']) { diff --git a/src/ui/components/FaDrawer/index.ts b/src/ui/components/FaDrawer/index.ts index 2d3e2a4a..848af68d 100644 --- a/src/ui/components/FaDrawer/index.ts +++ b/src/ui/components/FaDrawer/index.ts @@ -30,6 +30,7 @@ export interface DrawerProps { closeOnClickOverlay?: boolean closeOnPressEscape?: boolean destroyOnClose?: boolean + openAutoFocus?: boolean contentClass?: HTMLAttributes['class'] headerClass?: HTMLAttributes['class'] footerClass?: HTMLAttributes['class'] diff --git a/src/ui/components/FaDrawer/index.vue b/src/ui/components/FaDrawer/index.vue index 48a2dd90..97a44829 100644 --- a/src/ui/components/FaDrawer/index.vue +++ b/src/ui/components/FaDrawer/index.vue @@ -38,6 +38,7 @@ const props = withDefaults( closeOnClickOverlay: true, closeOnPressEscape: true, destroyOnClose: true, + openAutoFocus: false, }, ) @@ -135,6 +136,13 @@ async function onCancel() { } } +function handleOpenAutoFocus(e: Event) { + if (!props.openAutoFocus) { + e.preventDefault() + e.stopPropagation() + } +} + function handleFocusOutside(e: Event) { e.preventDefault() e.stopPropagation() @@ -179,7 +187,7 @@ function handleAnimationEnd() { })" :side="props.side" :force-mount="forceMount" - @open-auto-focus="handleFocusOutside" + @open-auto-focus="handleOpenAutoFocus" @close-auto-focus="handleFocusOutside" @focus-outside="handleFocusOutside" @pointer-down-outside="handleClickOutside" @@ -209,15 +217,11 @@ function handleAnimationEnd() { -
- -
- -
-
- -
-
+
+ +
+
+
- -
- -
-
- -
-
+
+ +
+
+ +