Skip to content

Prevent open change when clicking dropdown item #2982

Closed Answered by yf-yang
yf-yang asked this question in Help
Discussion options

You must be logged in to vote

preventDefault in onSelect handler

reference:

const handleSelect = () => {
const menuItem = ref.current;
if (!disabled && menuItem) {
const itemSelectEvent = new CustomEvent(ITEM_SELECT, { bubbles: true, cancelable: true });
menuItem.addEventListener(ITEM_SELECT, (event) => onSelect?.(event), { once: true });
dispatchDiscreteCustomEvent(menuItem, itemSelectEvent);
if (itemSelectEvent.defaultPrevented) {
isPointerDownRef.current = false;
} else {
rootContext.onClose();
}
}
};

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yf-yang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant