Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onClickOutside is called even when user clicks inside Picker #917

Open
harastaivan opened this issue May 27, 2024 · 0 comments
Open

onClickOutside is called even when user clicks inside Picker #917

harastaivan opened this issue May 27, 2024 · 0 comments

Comments

@harastaivan
Copy link

When using '@emoji-mart/react' Picker onClickOutside callback is called every time user clicks anything, even when we click inside the Picker component.

First I tried to not use onClickOutside prop at all.

I tried these hooks:

Tried to pass ref to

  • the parent component where picker is rendered
  • to Picker's pickerRef

Only workaround I could find was wrapping the Picker onClickOutside prop.

import data from '@emoji-mart/data';
import Picker from '@emoji-mart/react';

export interface EmojiPickerProps {
    onEmojiSelect: (emoji: Emoji) => void;
    onClickOutside: (event: PointerEvent) => void;
}

export const EmojiPicker = (props: EmojiPickerProps) => {
    return (
        <Picker
            data={data}
            {...props}
            onClickOutside={(event: PointerEvent) => {
                // Note: onClickOutside is called even when user clicks inside Picker

                const emojiPicker = document.querySelector('em-emoji-picker');
                const clickedInsideEmojiPicker = event.composedPath().includes(emojiPicker!);

                if (!clickedInsideEmojiPicker) {
                    props.onClickOutside(event);
                }
            }}
        />
    );
};

Why did previous attempts didn't work, does it relate to Shadow DOM rendering?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant