Skip to content

Commit 269269c

Browse files
authored
[🚑️][Menu]: Fix keyboard interactions on RTL (#96)
* Add keyboard interaction for RTL direction * Update version
1 parent 1e3126b commit 269269c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/Menu/Menu.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
import {
1717
componentWithForwardedRef,
1818
dispatchDiscreteCustomEvent,
19+
getDirection,
1920
useDeterministicId,
2021
useEventCallback,
2122
useEventListener,
@@ -244,6 +245,12 @@ const MenuBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
244245
activeElement,
245246
);
246247

248+
const dir = getDirection(event.currentTarget as HTMLElement);
249+
250+
const sameDirectionKey = dir === "rtl" ? SystemKeys.LEFT : SystemKeys.RIGHT;
251+
const oppositeDirectionKey =
252+
dir === "rtl" ? SystemKeys.RIGHT : SystemKeys.LEFT;
253+
247254
if (currentFocusedElement) {
248255
switch (event.key) {
249256
case SystemKeys.ESCAPE: {
@@ -322,7 +329,7 @@ const MenuBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
322329
break;
323330
}
324331

325-
case SystemKeys.LEFT: {
332+
case oppositeDirectionKey: {
326333
event.preventDefault();
327334

328335
const { item } = currentFocusedElement;
@@ -346,7 +353,7 @@ const MenuBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
346353
break;
347354
}
348355

349-
case SystemKeys.RIGHT: {
356+
case sameDirectionKey: {
350357
event.preventDefault();
351358

352359
const { item } = currentFocusedElement;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@styleless-ui/react",
3-
"version": "1.0.0-rc.4",
3+
"version": "1.0.0-rc.5",
44
"description": "Completely unstyled, headless and accessible React UI components.",
55
"author": "mimshins <mostafa.sh.coderino@gmail.com>",
66
"license": "MIT",

0 commit comments

Comments
 (0)