Skip to content

Commit

Permalink
refactor: radio/checkbox选中判断改回正则 (#2927)
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 authored Nov 24, 2023
1 parent 4a8eba3 commit c30f142
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/_common
4 changes: 2 additions & 2 deletions src/checkbox/hooks/useKeyboardEvent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const CHECKED_CODE = ['Enter', 'Space'];
import { CHECKED_CODE_REG } from '../../_common/js/common';

export function useKeyboardEvent(handleChange: (e: Event) => void) {
const keyboardEventListener = (e: KeyboardEvent) => {
const isCheckedCode = CHECKED_CODE.includes(e.key) || CHECKED_CODE.includes(e.code);
const isCheckedCode = CHECKED_CODE_REG.test(e.key) || CHECKED_CODE_REG.test(e.code);
if (isCheckedCode) {
e.preventDefault();
const { disabled } = (e.currentTarget as HTMLElement).querySelector('input');
Expand Down
4 changes: 2 additions & 2 deletions src/radio/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { emitEvent } from '../utils/event';
import { getClassPrefixMixins } from '../config-provider/config-receiver';
import mixins from '../utils/mixins';
import { off, on } from '../utils/dom';
import { CHECKED_CODE } from '../checkbox/hooks/useKeyboardEvent';
import { CHECKED_CODE_REG } from '../_common/js/common';

const classPrefixMixins = getClassPrefixMixins('radio-group');

Expand Down Expand Up @@ -114,7 +114,7 @@ export default mixins(classPrefixMixins).extend({

// 注意:此处会还原区分 数字 和 数字字符串
checkRadioInGroup(e: KeyboardEvent) {
const isCheckedCode = CHECKED_CODE.includes(e.key) || CHECKED_CODE.includes(e.code);
const isCheckedCode = CHECKED_CODE_REG.test(e.key) || CHECKED_CODE_REG.test(e.code);
if (isCheckedCode) {
e.preventDefault();
const inputNode = (e.target as HTMLElement).querySelector('input');
Expand Down

0 comments on commit c30f142

Please sign in to comment.