Close sticker picker on Escape keyup
This commit is contained in:
parent
020d78e62b
commit
46b4cf56a3
3 changed files with 34 additions and 0 deletions
|
@ -81,6 +81,13 @@ export const StickerButton = React.memo(
|
||||||
[setOpen, onPickSticker]
|
[setOpen, onPickSticker]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleClose = React.useCallback(
|
||||||
|
() => {
|
||||||
|
setOpen(false);
|
||||||
|
},
|
||||||
|
[setOpen]
|
||||||
|
);
|
||||||
|
|
||||||
const handleClickAddPack = React.useCallback(
|
const handleClickAddPack = React.useCallback(
|
||||||
() => {
|
() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
@ -253,6 +260,7 @@ export const StickerButton = React.memo(
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
style={style}
|
style={style}
|
||||||
packs={installedPacks}
|
packs={installedPacks}
|
||||||
|
onClose={handleClose}
|
||||||
onClickAddPack={handleClickAddPack}
|
onClickAddPack={handleClickAddPack}
|
||||||
onPickSticker={handlePickSticker}
|
onPickSticker={handlePickSticker}
|
||||||
recentStickers={recentStickers}
|
recentStickers={recentStickers}
|
||||||
|
|
|
@ -156,6 +156,7 @@ const packs = [
|
||||||
sticker3,
|
sticker3,
|
||||||
{ ...sticker2, id: 9999 },
|
{ ...sticker2, id: 9999 },
|
||||||
]}
|
]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
@ -206,6 +207,7 @@ const packs = [
|
||||||
i18n={util.i18n}
|
i18n={util.i18n}
|
||||||
packs={packs}
|
packs={packs}
|
||||||
recentStickers={[]}
|
recentStickers={[]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
@ -222,6 +224,7 @@ const packs = [
|
||||||
i18n={util.i18n}
|
i18n={util.i18n}
|
||||||
packs={[]}
|
packs={[]}
|
||||||
recentStickers={[]}
|
recentStickers={[]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
@ -249,6 +252,7 @@ const packs = [
|
||||||
i18n={util.i18n}
|
i18n={util.i18n}
|
||||||
packs={packs}
|
packs={packs}
|
||||||
recentStickers={[]}
|
recentStickers={[]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
@ -277,6 +281,7 @@ const packs = [
|
||||||
i18n={util.i18n}
|
i18n={util.i18n}
|
||||||
packs={packs}
|
packs={packs}
|
||||||
recentStickers={[]}
|
recentStickers={[]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
@ -312,6 +317,7 @@ const packs = [
|
||||||
i18n={util.i18n}
|
i18n={util.i18n}
|
||||||
packs={packs}
|
packs={packs}
|
||||||
recentStickers={[]}
|
recentStickers={[]}
|
||||||
|
onClose={() => console.log('onClose')}
|
||||||
onClickAddPack={() => console.log('onClickAddPack')}
|
onClickAddPack={() => console.log('onClickAddPack')}
|
||||||
onPickSticker={(packId, stickerId) =>
|
onPickSticker={(packId, stickerId) =>
|
||||||
console.log('onPickSticker', { packId, stickerId })
|
console.log('onPickSticker', { packId, stickerId })
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { LocalizerType } from '../../types/Util';
|
||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
readonly i18n: LocalizerType;
|
readonly i18n: LocalizerType;
|
||||||
|
readonly onClose: () => unknown;
|
||||||
readonly onClickAddPack: () => unknown;
|
readonly onClickAddPack: () => unknown;
|
||||||
readonly onPickSticker: (packId: string, stickerId: number) => unknown;
|
readonly onPickSticker: (packId: string, stickerId: number) => unknown;
|
||||||
readonly packs: ReadonlyArray<StickerPackType>;
|
readonly packs: ReadonlyArray<StickerPackType>;
|
||||||
|
@ -59,6 +60,7 @@ export const StickerPicker = React.memo(
|
||||||
i18n,
|
i18n,
|
||||||
packs,
|
packs,
|
||||||
recentStickers,
|
recentStickers,
|
||||||
|
onClose,
|
||||||
onClickAddPack,
|
onClickAddPack,
|
||||||
onPickSticker,
|
onPickSticker,
|
||||||
showPickerHint,
|
showPickerHint,
|
||||||
|
@ -96,6 +98,24 @@ export const StickerPicker = React.memo(
|
||||||
[setPacksPage]
|
[setPacksPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Handle escape key
|
||||||
|
React.useEffect(
|
||||||
|
() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('keyup', handler);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keyup', handler);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[onClose]
|
||||||
|
);
|
||||||
|
|
||||||
const isEmpty = stickers.length === 0;
|
const isEmpty = stickers.length === 0;
|
||||||
const downloadError =
|
const downloadError =
|
||||||
selectedPack &&
|
selectedPack &&
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue