Skip to content

Commit 16e7397

Browse files
authored
fix 8072: dropdown wrong behavior (#8243)
* fix 8072: dropdown wrong behavior * fix: cursor navigation with left/right arrow keys fix cursor movement on text when editable is not present and navigating with left/right arrow keys
1 parent ffd3b5c commit 16e7397

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

components/lib/dropdown/Dropdown.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ export const Dropdown = React.memo(
222222
break;
223223

224224
case 'Home':
225-
onHomeKey(event);
225+
onHomeKey(event, props.editable);
226226
break;
227227

228228
case 'End':
229-
onEndKey(event);
229+
onEndKey(event, props.editable);
230230
break;
231231

232232
case 'PageDown':
@@ -451,12 +451,16 @@ export const Dropdown = React.memo(
451451
};
452452

453453
const onArrowLeftKey = (event, pressedInInputText = false) => {
454-
pressedInInputText && setFocusedOptionIndex(-1);
454+
if (!pressedInInputText) return;
455+
456+
props.editable && DomHandler.focus(inputRef.current);
457+
setFocusedOptionIndex(-1);
455458
};
456459

457460
const onHomeKey = (event, pressedInInputText = false) => {
458461
if (pressedInInputText) {
459-
event.currentTarget.setSelectionRange(0, 0);
462+
DomHandler.focus(inputRef.current);
463+
inputRef.current.setSelectionRange(0, 0);
460464
setFocusedOptionIndex(-1);
461465
} else {
462466
changeFocusedOptionIndex(event, findFirstOptionIndex());
@@ -469,9 +473,10 @@ export const Dropdown = React.memo(
469473

470474
const onEndKey = (event, pressedInInputText = false) => {
471475
if (pressedInInputText) {
472-
const target = event.currentTarget;
476+
const target = inputRef.current;
473477
const len = target.value.length;
474478

479+
DomHandler.focus(target);
475480
target.setSelectionRange(len, len);
476481
setFocusedOptionIndex(-1);
477482
} else {

0 commit comments

Comments
 (0)