Skip to content

Commit 392a014

Browse files
committed
Fix keycode failures and update test-utils
1 parent 89397ea commit 392a014

File tree

9 files changed

+634
-749
lines changed

9 files changed

+634
-749
lines changed

src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20615,7 +20615,10 @@ Requires React 18.",
2061520615
},
2061620616
{
2061720617
"description": "Inserts text at a specified position. Only supported when \`menus\` or \`tokens\` is defined.
20618-
Triggers input events and menu detection.",
20618+
Triggers input events and menu detection.
20619+
20620+
When pinned reference tokens are present, \`caretStart\` and \`caretEnd\` are automatically
20621+
shifted to account for their positions.",
2061920622
"name": "insertText",
2062020623
"parameters": [
2062120624
{
@@ -40890,8 +40893,7 @@ If not specified, the method returns the result text that is currently displayed
4089040893
},
4089140894
},
4089240895
{
40893-
"description": "Finds the contentEditable element used when menus are defined.
40894-
Returns null if the component does not have menus defined.",
40896+
"description": "Finds the contentEditable element used when \`menus\` or \`tokens\` is defined.",
4089540897
"name": "findContentEditableElement",
4089640898
"parameters": [],
4089740899
"returnType": {
@@ -40920,8 +40922,8 @@ Returns null if the component does not have menus defined.",
4092040922
{
4092140923
"description": "Finds the native textarea element.
4092240924

40923-
Note: When menus are defined, the component uses a contentEditable element instead of a textarea.
40924-
In this case, use findContentEditableElement() or getValue() instead.",
40925+
Note: When \`menus\` or \`tokens\` is defined, the component uses a contentEditable element instead of a textarea.
40926+
In this case, use findContentEditableElement() instead.",
4092540927
"name": "findNativeTextarea",
4092640928
"parameters": [],
4092740929
"returnType": {
@@ -40935,7 +40937,7 @@ In this case, use findContentEditableElement() or getValue() instead.",
4093540937
},
4093640938
},
4093740939
{
40938-
"description": "Finds the menu dropdown (always in portal due to expandToViewport=true).",
40940+
"description": "Finds the menu dropdown when \`menus\` or \`tokens\` is defined.",
4093940941
"name": "findOpenMenu",
4094040942
"parameters": [],
4094140943
"returnType": {
@@ -40973,19 +40975,11 @@ In this case, use findContentEditableElement() or getValue() instead.",
4097340975
{
4097440976
"description": "Gets the value of the component.
4097540977

40976-
Returns the current value of the textarea.",
40977-
"name": "getTextareaValue",
40978-
"parameters": [],
40979-
"returnType": {
40980-
"isNullable": false,
40981-
"name": "string",
40982-
},
40983-
},
40984-
{
40985-
"description": "Gets the value of the component.
40978+
Returns the current value of the textarea.
4098640979

40987-
Returns the current value of the textarea (when no menus are defined) or the text content of the contentEditable element (when menus are defined).",
40988-
"name": "getValue",
40980+
When \`menus\` or \`tokens\` is defined, the component uses a contentEditable element.
40981+
Use findContentEditableElement().getElement().textContent instead.",
40982+
"name": "getTextareaValue",
4098940983
"parameters": [],
4099040984
"returnType": {
4099140985
"isNullable": false,
@@ -41038,7 +41032,10 @@ Returns the current value of the textarea (when no menus are defined) or the tex
4103841032
},
4103941033
},
4104041034
{
41041-
"description": "Sets the value of the textarea and calls the onChange handler.",
41035+
"description": "Sets the value of the textarea and calls the onChange handler.
41036+
41037+
When \`menus\` or \`tokens\` is defined, the component uses a contentEditable element
41038+
and this method will have no effect.",
4104241039
"name": "setTextareaValue",
4104341040
"parameters": [
4104441041
{
@@ -50488,8 +50485,7 @@ If not specified, the method returns the result text that is currently displayed
5048850485
},
5048950486
},
5049050487
{
50491-
"description": "Finds the contentEditable element used when menus are defined.
50492-
Returns null if the component does not have menus defined.",
50488+
"description": "Finds the contentEditable element used when \`menus\` or \`tokens\` is defined.",
5049350489
"name": "findContentEditableElement",
5049450490
"parameters": [],
5049550491
"returnType": {
@@ -50508,8 +50504,8 @@ Returns null if the component does not have menus defined.",
5050850504
{
5050950505
"description": "Finds the native textarea element.
5051050506

50511-
Note: When menus are defined, the component uses a contentEditable element instead of a textarea.
50512-
In this case, use findContentEditableElement() or getValue() instead.",
50507+
Note: When \`menus\` or \`tokens\` is defined, the component uses a contentEditable element instead of a textarea.
50508+
In this case, use findContentEditableElement() instead.",
5051350509
"name": "findNativeTextarea",
5051450510
"parameters": [],
5051550511
"returnType": {
@@ -50518,7 +50514,7 @@ In this case, use findContentEditableElement() or getValue() instead.",
5051850514
},
5051950515
},
5052050516
{
50521-
"description": "Finds the menu dropdown (always in portal due to expandToViewport=true).",
50517+
"description": "Finds the menu dropdown when \`menus\` or \`tokens\` is defined.",
5052250518
"name": "findOpenMenu",
5052350519
"parameters": [],
5052450520
"returnType": {

src/internal/keycode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export enum KeyCode {
99
end = 35,
1010
home = 36,
1111
backspace = 8,
12-
delete = 46,
1312
space = 32,
1413
down = 40,
1514
left = 37,
@@ -18,5 +17,10 @@ export enum KeyCode {
1817
escape = 27,
1918
enter = 13,
2019
tab = 9,
21-
a = 65,
2220
}
21+
22+
// Additional keycodes used by prompt-input that are not part of the
23+
// test-utils-core KeyCode enum. Defined separately to keep the enum
24+
// compatible with the external type used by ElementWrapper.keydown().
25+
export const KeyCodeDelete = 46;
26+
export const KeyCodeA = 65;

src/internal/utils/handle-key.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { getIsRtl } from '@cloudscape-design/component-toolkit/internal';
44

5-
import { KeyCode } from '../keycode';
5+
import { KeyCode, KeyCodeA, KeyCodeDelete } from '../keycode';
66
import { isHTMLElement, isSVGElement } from './dom';
77

88
export function isEventLike(event: any): event is EventLike {
@@ -64,7 +64,7 @@ export default function handleKey(
6464
}
6565
) {
6666
switch (event.keyCode) {
67-
case KeyCode.a:
67+
case KeyCodeA:
6868
if ((event.ctrlKey || event.metaKey) && onSelectAll) {
6969
onSelectAll();
7070
} else {
@@ -74,7 +74,7 @@ export default function handleKey(
7474
case KeyCode.backspace:
7575
onBackspace?.();
7676
break;
77-
case KeyCode.delete:
77+
case KeyCodeDelete:
7878
onDelete?.();
7979
break;
8080
case KeyCode.down:

0 commit comments

Comments
 (0)