Skip to content

Commit

Permalink
feat(radio): 空格键也可触发选中 (#2638)
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 authored Dec 2, 2023
1 parent 6bbd80f commit 14e36e4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/radio/useKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MutableRefObject, useEffect, ChangeEvent, KeyboardEvent } from 'react';
import { CHECKED_CODE_REG } from '../_common/js/common';
import { off, on } from '../_util/dom';

/** 键盘操作 */
Expand All @@ -7,7 +8,7 @@ export default function useKeyboard(
setInnerValue: (value: any, context: { e: ChangeEvent<any> }) => void,
) {
const checkRadioInGroup = (e: KeyboardEvent) => {
if (/enter/i.test(e.key) || /enter/i.test(e.code)) {
if (CHECKED_CODE_REG.test(e.key) || CHECKED_CODE_REG.test(e.code)) {
const inputNode = (e.target as HTMLElement).querySelector('input');
const data = inputNode?.dataset || {};
if (inputNode.checked && data.allowUncheck) {
Expand Down

0 comments on commit 14e36e4

Please sign in to comment.