From 5a7b6e6a065d216fd6140433db2211682131f28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 30 Aug 2021 21:24:34 +0200 Subject: [PATCH 1/2] Trap Tab key in emoji selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/emoji_selector.js | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/soapbox/components/emoji_selector.js b/app/soapbox/components/emoji_selector.js index 572f63a86..b47166228 100644 --- a/app/soapbox/components/emoji_selector.js +++ b/app/soapbox/components/emoji_selector.js @@ -35,21 +35,38 @@ class EmojiSelector extends ImmutablePureComponent { } } - handleKeyUp = i => e => { + _selectPreviousEmoji = i => { + if (i !== 0) { + this.node.querySelector(`.emoji-react-selector__emoji:nth-child(${i})`).focus(); + } else { + this.node.querySelector('.emoji-react-selector__emoji:last-child').focus(); + } + }; + + _selectNextEmoji = i => { + if (i !== this.props.allowedEmoji.size - 1) { + this.node.querySelector(`.emoji-react-selector__emoji:nth-child(${i + 2})`).focus(); + } else { + this.node.querySelector('.emoji-react-selector__emoji:first-child').focus(); + } + }; + + handleKeyDown = i => e => { const { onUnfocus } = this.props; switch (e.key) { + case 'Tab': + e.preventDefault(); + if (e.shiftKey) this._selectPreviousEmoji(i); + else this._selectNextEmoji(i); + break; case 'Left': case 'ArrowLeft': - if (i !== 0) { - this.node.querySelector(`.emoji-react-selector__emoji:nth-child(${i})`).focus(); - } + this._selectPreviousEmoji(i); break; case 'Right': case 'ArrowRight': - if (i !== this.props.allowedEmoji.size - 1) { - this.node.querySelector(`.emoji-react-selector__emoji:nth-child(${i + 2})`).focus(); - } + this._selectNextEmoji(i); break; case 'Escape': onUnfocus(); @@ -94,7 +111,7 @@ class EmojiSelector extends ImmutablePureComponent { className='emoji-react-selector__emoji' dangerouslySetInnerHTML={{ __html: emojify(emoji) }} onClick={this.handleReact(emoji)} - onKeyUp={this.handleKeyUp(i, emoji)} + onKeyDown={this.handleKeyDown(i, emoji)} tabIndex={(visible || focused) ? 0 : -1} /> ))} From b8a9a17c099808c0f619677d05ec7d793f7aa89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 30 Aug 2021 21:54:39 +0200 Subject: [PATCH 2/2] Update emoji selector snapshot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../__snapshots__/emoji_selector-test.js.snap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/soapbox/components/__tests__/__snapshots__/emoji_selector-test.js.snap b/app/soapbox/components/__tests__/__snapshots__/emoji_selector-test.js.snap index 17833fc33..06d7764ec 100644 --- a/app/soapbox/components/__tests__/__snapshots__/emoji_selector-test.js.snap +++ b/app/soapbox/components/__tests__/__snapshots__/emoji_selector-test.js.snap @@ -19,7 +19,7 @@ exports[` renders correctly 1`] = ` } } onClick={[Function]} - onKeyUp={[Function]} + onKeyDown={[Function]} tabIndex={-1} />