Skip to content

Commit d3fb27d

Browse files
committed
Refactor arrow key handling in toolbar and picker components for improved readability
1 parent 06661f7 commit d3fb27d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

packages/quill/src/modules/toolbar.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,24 @@ class Toolbar extends Module<ToolbarProps> {
153153
var target = e.currentTarget;
154154
if (!target) return;
155155

156-
switch (e.key) {
157-
case 'ArrowLeft':
158-
case 'ArrowRight':
156+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
159157
this.updateTabIndexes(target, e.key);
160-
break;
161-
}
158+
}
162159
}
163160

164161
updateTabIndexes(target: EventTarget, key: string) {
165162
const currentIndex = this.controls.findIndex(control => control[1] === target);
166163
const currentItem = this.controls[currentIndex][1];
167164
currentItem.tabIndex = -1;
168165

169-
let nextIndex;
166+
let nextIndex: number | null = null;
170167
if (key === 'ArrowLeft') {
171168
nextIndex = currentIndex === 0 ? this.controls.length - 1 : currentIndex - 1;
172169
} else if (key === 'ArrowRight') {
173170
nextIndex = currentIndex === this.controls.length - 1 ? 0 : currentIndex + 1;
174171
}
175172

176-
if (nextIndex === undefined) return;
173+
if (nextIndex === null) return;
177174
const nextItem = this.controls[nextIndex][1];
178175
if (nextItem.tagName === 'SELECT') {
179176
const qlPickerLabel = nextItem.previousElementSibling?.querySelectorAll('.ql-picker-label')[0];

packages/quill/src/ui/picker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ class Picker {
129129
var target = e.currentTarget;
130130
if (!target) return;
131131

132-
switch (e.key) {
133-
case 'ArrowLeft':
134-
case 'ArrowRight':
132+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
135133
this.updateTabIndexes(target, e.key);
136-
break;
137-
}
134+
}
138135
}
139136

140137
updateTabIndexes(target: EventTarget, key: string) {

0 commit comments

Comments
 (0)