Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 误判断删除键(backspace)是空格键(space) #2905

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_REG = /(enter|space)/i;
export const CHECKED_CODE = ['Enter', 'Space'];

export function useKeyboardEvent(handleChange: (e: Event) => void) {
const keyboardEventListener = (e: KeyboardEvent) => {
const isCheckedCode = CHECKED_CODE_REG.test(e.key) || CHECKED_CODE_REG.test(e.code);
const isCheckedCode = CHECKED_CODE.includes(e.key) || CHECKED_CODE.includes(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_REG } from '../checkbox/hooks/useKeyboardEvent';
import { CHECKED_CODE } from '../checkbox/hooks/useKeyboardEvent';

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_REG.test(e.key) || CHECKED_CODE_REG.test(e.code);
const isCheckedCode = CHECKED_CODE.includes(e.key) || CHECKED_CODE.includes(e.code);
if (isCheckedCode) {
e.preventDefault();
const inputNode = (e.target as HTMLElement).querySelector('input');
Expand Down