Skip to content

Commit 5625fdf

Browse files
committed
feat: better pointerDown for mention-item
1 parent 33c69a1 commit 5625fdf

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

packages/combobox/src/combobox-content.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface ComboboxContentProps
4343
/**
4444
* Event handler called when a `pointerdown` event happens outside of the content.
4545
*
46-
* Can be used to prevent the content from closing when the pointer is outside of the content.
46+
* Can be used to prevent the popover from closing when the pointer is outside of the content.
4747
*/
4848
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
4949
}

packages/mention/src/mention-content.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ interface MentionContentProps
3737
/**
3838
* Event handler called when the `Escape` key is pressed.
3939
*
40-
* Can be used to prevent input value from being reset on `Escape` key press.
40+
* Can be used to prevent the popover from closing when the `Escape` key is pressed.
4141
*/
4242
onEscapeKeyDown?: (event: KeyboardEvent) => void;
4343

4444
/**
4545
* Event handler called when a `pointerdown` event happens outside of the content.
4646
*
47-
* Can be used to prevent the content from closing when the pointer is outside of the content.
47+
* Can be used to prevent the popover from closing when the pointer is outside of the content.
4848
*/
4949
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
5050
}

packages/mention/src/mention-item.tsx

+7-11
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ const MentionItem = React.forwardRef<ItemElement, MentionItemProps>(
8484
ref={composedRef}
8585
onClick={composeEventHandlers(itemProps.onClick, () => {
8686
if (isDisabled) return;
87-
const input = context.inputRef.current;
88-
if (!input) return;
87+
const inputElement = context.inputRef.current;
88+
if (!inputElement) return;
8989

90-
const selectionStart = input.selectionStart ?? 0;
91-
const lastTriggerIndex = input.value.lastIndexOf(
90+
const selectionStart = inputElement.selectionStart ?? 0;
91+
const lastTriggerIndex = inputElement.value.lastIndexOf(
9292
context.trigger,
9393
selectionStart,
9494
);
@@ -97,7 +97,7 @@ const MentionItem = React.forwardRef<ItemElement, MentionItemProps>(
9797
context.onMentionAdd(value, lastTriggerIndex);
9898
}
9999

100-
input.focus();
100+
inputElement.focus();
101101
})}
102102
onPointerDown={composeEventHandlers(
103103
itemProps.onPointerDown,
@@ -111,12 +111,8 @@ const MentionItem = React.forwardRef<ItemElement, MentionItemProps>(
111111
target.releasePointerCapture(event.pointerId);
112112
}
113113

114-
if (
115-
event.button === 0 &&
116-
event.ctrlKey === false &&
117-
event.pointerType === "mouse"
118-
) {
119-
// prevent item from stealing focus from the input
114+
if (event.button === 0 && event.ctrlKey === false) {
115+
// prevent item from stealing focus from the input for both mouse and touch
120116
event.preventDefault();
121117
}
122118
},

0 commit comments

Comments
 (0)