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

View File

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