Skip to content

Commit 1c5259a

Browse files
committed
fix: exclude input with value from keyboard arrow navigation
1 parent 3f37add commit 1c5259a

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

packages/docs/stories/src/test-elevation.stories.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
useSnackbar,
1717
Manager,
1818
Icon,
19+
Input,
1920
} from "react-ck";
2021
import { faker } from "@faker-js/faker";
2122
import { IconVerticalDots } from "@react-ck/icon/icons/IconVerticalDots";
@@ -301,12 +302,15 @@ const Counter = (): React.ReactElement => {
301302
);
302303
};
303304

304-
const SelectField = (): React.ReactElement => (
305-
<Select placeholder="Select">
306-
<Select.Option>1</Select.Option>
307-
<Select.Option>2</Select.Option>
308-
<Select.Option>3</Select.Option>
309-
</Select>
305+
const Fields = (): React.ReactElement => (
306+
<>
307+
<Input placeholder="Input" />
308+
<Select placeholder="Select">
309+
<Select.Option>1</Select.Option>
310+
<Select.Option>2</Select.Option>
311+
<Select.Option>3</Select.Option>
312+
</Select>
313+
</>
310314
);
311315

312316
const AllItems = ({ children }: { readonly children: React.ReactNode }): React.ReactElement => {
@@ -355,14 +359,14 @@ const App = (): React.ReactElement => (
355359

356360
<Counter />
357361

358-
<SelectField />
362+
<Fields />
359363

360364
<AllItems>
361365
<Text>{faker.lorem.paragraph()}</Text>
362366

363367
<Counter />
364368

365-
<SelectField />
369+
<Fields />
366370

367371
<Actions />
368372
</AllItems>

packages/utils/keyboard-controls/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ export class KeyboardControls {
6060
private handleFocusWithArrows = (e: KeyboardEvent): void => {
6161
const currentElement = document.activeElement;
6262

63-
if (!currentElement) return;
63+
// skip if no focused element
64+
// or content editable element
65+
// or current element is an input or textarea with value
66+
if (
67+
!currentElement ||
68+
(currentElement instanceof HTMLElement && currentElement.isContentEditable) ||
69+
(currentElement instanceof HTMLInputElement &&
70+
currentElement.value &&
71+
(currentElement.tagName === "INPUT" || currentElement.tagName === "TEXTAREA"))
72+
)
73+
return;
6474

6575
const { focusableElements } = getFocusableElements({
6676
container: this.container,

0 commit comments

Comments
 (0)