Skip to content

Commit e9938ea

Browse files
DrJonkiantfu
andauthored
feat(useDraggable): add buttons option (#4084)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 13e367c commit e9938ea

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/core/useDraggable/component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const UseDraggable = /* #__PURE__ */ defineComponent<UseDraggableProps>({
3535
'onMove',
3636
'onEnd',
3737
'disabled',
38+
'buttons',
3839
] as unknown as undefined,
3940
setup(props, { slots }) {
4041
const target = ref()

packages/core/useDraggable/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ export interface UseDraggableOptions {
9797
* @default false
9898
*/
9999
disabled?: MaybeRefOrGetter<boolean>
100+
101+
/**
102+
* Mouse buttons that are allowed to trigger drag events.
103+
*
104+
* - `0`: Main button, usually the left button or the un-initialized state
105+
* - `1`: Auxiliary button, usually the wheel button or the middle button (if present)
106+
* - `2`: Secondary button, usually the right button
107+
* - `3`: Fourth button, typically the Browser Back button
108+
* - `4`: Fifth button, typically the Browser Forward button
109+
*
110+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value
111+
* @default [0]
112+
*/
113+
buttons?: MaybeRefOrGetter<number[]>
100114
}
101115

102116
/**
@@ -123,6 +137,7 @@ export function useDraggable(
123137
draggingElement = defaultWindow,
124138
containerElement,
125139
handle: draggingHandle = target,
140+
buttons = [0],
126141
} = options
127142

128143
const position = ref<Position>(
@@ -145,7 +160,7 @@ export function useDraggable(
145160
}
146161

147162
const start = (e: PointerEvent) => {
148-
if (e.button !== 0)
163+
if (!toValue(buttons).includes(e.button))
149164
return
150165
if (toValue(options.disabled) || !filterEvent(e))
151166
return

0 commit comments

Comments
 (0)