0

我有一个Input像里面的脉轮 UI 元素Formik Form

import { Formik, useField, Form, useFormikContext } from "formik";
import {
  Input } from "@chakra-ui/react";

          <Formik
            // setup stuff
          >
            <Form>
              <Input
                id={field.name}
                onChange={field.onChange}
                placeholder={placeholder}
                value={field.value}
                onKeyPress={(event) => {
                  console.log("event = ", event)
                  console.log("event.key = ", event.key)
                  if (event.key === "Backspace") {
                    console.log("pressed backspace")
                  }
                }}
              />

我得到了字母键的打印输出,但是当我delete在 Google Chrome 版本 91.0.4472.114(官方版本)(x86_64)中按我的 macOS 10.15.7 上的键时无法打印输出

有人知道我做错了什么吗?

这是event我在键盘上按字母 R 时的打印输出

event =  
SyntheticBaseEvent {_reactName: "onKeyPress", _targetInst: null, type: "keypress", nativeEvent: KeyboardEvent, target: input#player3.chakra-input.css-1q4t59, …}
altKey: false
bubbles: true
cancelable: true
charCode: 82
code: "KeyS"
ctrlKey: false
currentTarget: null
defaultPrevented: false
detail: 0
eventPhase: 3
getModifierState: ƒ modifierStateGetter(keyArg)
isDefaultPrevented: ƒ functionThatReturnsFalse()
isPropagationStopped: ƒ functionThatReturnsFalse()
isTrusted: true
key: "R"
keyCode: 0
locale: undefined
location: 0
metaKey: false
nativeEvent: KeyboardEvent {isTrusted: true, key: "R", code: "KeyS", location: 0, ctrlKey: false, …}
repeat: false
shiftKey: true
target: input#player3.chakra-input.css-1q4t59
timeStamp: 643207.7999999998
type: "keypress"
view: Window {window: Window, self: Window, document: document, name: "", location: Location, …}
which: 82
_reactName: "onKeyPress"
_targetInst: null
4

0 回答 0