Skip to content

Commit 1bf46cf

Browse files
committed
fix(list): open quick action on item edge when no movement or modifiers
1 parent 2a20b41 commit 1bf46cf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/components/common/list/ListItem.vue

+19-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { PosterItem } from '~/models/poster.model';
1616
import ListItemPanel from '~/components/common/list/ListItemPanel.vue';
1717
import PosterComponent from '~/components/common/poster/PosterComponent.vue';
1818
import { type ListScrollItem, ListScrollItemType } from '~/models/list-scroll.model';
19+
import { useAppStateStoreRefs } from '~/stores/app-state.store';
1920
import { useI18n } from '~/utils/i18n.utils';
2021
2122
const props = defineProps({
@@ -119,9 +120,11 @@ const i18n = useI18n('list', 'item');
119120
const { item, noHeader, nextHasHeader, poster, hideDate, scrollIntoView, height, color } =
120121
toRefs(props);
121122
123+
const { root } = useAppStateStoreRefs();
122124
const itemRef = ref<
123125
Omit<InstanceType<typeof NTimelineItem>, '$el'> & { $el?: HTMLDivElement }
124126
>();
127+
const buttons = ref<InstanceType<typeof NButtonGroup> & { $el?: HTMLDivElement }>();
125128
126129
const focusin = ref(false);
127130
const focusTimeout = ref<ReturnType<typeof setTimeout>>();
@@ -138,11 +141,26 @@ const toggleFocusin = (focus: boolean) => {
138141
139142
const open = ref(false);
140143
const dragged = ref(0);
144+
145+
const hoverTimeout = ref<ReturnType<typeof setTimeout>>();
146+
const overOpen = (e: MouseEvent) => {
147+
clearTimeout(hoverTimeout.value);
148+
if (open.value) return;
149+
if (e.shiftKey || e.ctrlKey || e.shiftKey || e.metaKey) return;
150+
const offsetWidth = (root.value?.clientWidth ?? window.innerWidth) - e.clientX;
151+
if (offsetWidth > 50) return;
152+
hoverTimeout.value = setTimeout(() => {
153+
open.value = true;
154+
}, 100);
155+
};
156+
141157
const onHover = (_event: MouseEvent, _hover: boolean) => {
142158
emit('onHover', { item: item?.value, hover: _hover });
143159
itemRef.value?.$el?.focus({ preventScroll: true });
144160
open.value = _hover && (_event.altKey || _event.ctrlKey);
145161
if (!_hover) dragged.value = 0;
162+
if (!_hover) return clearTimeout(hoverTimeout.value);
163+
return overOpen(_event);
146164
};
147165
148166
const touchStart = ref<TouchEvent>();
@@ -153,7 +171,6 @@ const onTouchStart = (e: TouchEvent) => {
153171
initialDrag.value = dragged.value;
154172
};
155173
156-
const buttons = ref<InstanceType<typeof NButtonGroup> & { $el?: HTMLDivElement }>();
157174
const onToucheMove = (e: TouchEvent) => {
158175
const _width = buttons.value?.$el?.clientWidth;
159176
if (!_width) return;
@@ -238,6 +255,7 @@ const onClick = (e: MouseEvent | KeyboardEvent) =>
238255
@keydown.ctrl="open = !open"
239256
@mouseenter.passive="e => onHover(e, true)"
240257
@mouseleave.passive="e => onHover(e, false)"
258+
@mousemove.passive="overOpen"
241259
@touchstart.passive="onTouchStart"
242260
@touchmove.passive="onToucheMove"
243261
@touchend.passive="onTouchEnd"

0 commit comments

Comments
 (0)