fix: more reliable not closing emoji picker on shift key

This commit is contained in:
freeplay 2023-07-16 13:41:55 -04:00
parent 05477ee6b4
commit 5b5f997ecf
2 changed files with 6 additions and 29 deletions

View file

@ -195,7 +195,7 @@ const props = withDefaults(
);
const emit = defineEmits<{
(ev: "chosen", v: string): void;
(ev: "chosen", v: string, ev: MouseEvent): void;
}>();
const search = ref<HTMLInputElement>();
@ -436,7 +436,7 @@ function chosen(emoji: any, ev?: MouseEvent) {
}
const key = getKey(emoji);
emit("chosen", key);
emit("chosen", key, ev);
// 使
if (!pinned.value.includes(key)) {

View file

@ -58,29 +58,16 @@ const emit = defineEmits<{
const modal = ref<InstanceType<typeof MkModal>>();
const picker = ref<InstanceType<typeof MkEmojiPicker>>();
const isShiftKeyPressed = ref(false);
const keydownHandler = (e) => {
if (e.key === "Shift") {
isShiftKeyPressed.value = true;
}
};
const keyupHandler = (e) => {
if (e.key === "Shift") {
isShiftKeyPressed.value = false;
}
};
function checkForShift(ev?: MouseEvent) {
if (!isShiftKeyPressed.value) {
if (ev?.shiftKey) return;
modal.value?.close(ev);
}
}
function chosen(emoji: any) {
function chosen(emoji: any, ev: MouseEvent) {
emit("done", emoji);
checkForShift();
checkForShift(ev);
}
function opening() {
@ -91,16 +78,6 @@ function opening() {
}
picker.value?.focus();
}
onMounted(() => {
window.addEventListener("keydown", keydownHandler);
window.addEventListener("keyup", keyupHandler);
});
onBeforeUnmount(() => {
window.removeEventListener("keydown", keydownHandler);
window.removeEventListener("keyup", keyupHandler);
});
</script>
<style lang="scss" scoped>