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

feat: add 'Keys' variable to enum values and check for hotKeys #2463

Merged
merged 15 commits into from
Sep 10, 2024

Conversation

Nathon2Y
Copy link
Contributor

@Nathon2Y Nathon2Y commented Sep 2, 2024

中文模板 / Chinese Template

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Test Case
  • TypeScript definition update
  • Document improve
  • CI/CD improve
  • Branch sync
  • Other, please describe:

PR description

Fixes #

Changelog

🇨🇳 Chinese

  • Feat: 为组件新增Keys变量,并为用户定义快捷键添加有效性检查

🇺🇸 English

  • Feat: add 'Keys' variable to enum values and check for hotKeys

Checklist

  • Test or no need
  • Document or no need
  • Changelog or no need

Other

  • Skip Changelog

Additional information

Copy link

codesandbox-ci bot commented Sep 2, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 68320fe:

Sandbox Source
pr-story Configuration

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这啥

@@ -180,14 +230,14 @@ function Demo() {

| Property | Instructions | type | Default |
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|-----------|
| hotKeys | Define keyboard shortcut,[values](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values) | KeyboardEvent.key[] | - |
| blockDefault | Whether to prevent the default behavior of the shortcut | boolean | false |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成和原生一样的 preventDefault 吧

```jsx live=true
import React, { useState } from 'react';
import { HotKeys, Tag } from '@douyinfe/semi-ui';
import { HotKeys, Keys, Modal, Tag } from '@douyinfe/semi-ui';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把枚举的 Keys 放到 HotKeys 的static 属性上吧,不要让用户单独 import 了,有点分散

this.props.onClick();
notifyHotKey: () => {
if (this.props.onHotKey && typeof this.props.onHotKey === 'function') {
this.props.onHotKey();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.props.onHotKey?.() 然后不要忘记把事件 event 也作为入参

if (this.props.getListenerTarget) {
return this.props.getListenerTarget();
if (this.props.getListenerTarget && typeof this.props.getListenerTarget === 'function') {
return this.props.getListenerTarget?.();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了问号就不用 if 提前判空了

}
});

return commonKeyCnt === 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commonKeyCnt 大于一现在是不支持?如果检测到大于一的话,也给个报错吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在大于一就有报错

@DaiQiangReal DaiQiangReal merged commit c8ff557 into DouyinFE:release Sep 10, 2024
4 of 6 checks passed
Copy link

cypress bot commented Sep 10, 2024

semi-design    Run #2796

Run Properties:  status check failed Failed #2796  •  git commit c8ff5578e0: Merge pull request #2463 from Nathon2Y/feat/KeyboardShortCut
Project semi-design
Branch Review release
Run status status check failed Failed #2796
Run duration 10m 11s
Commit git commit c8ff5578e0: Merge pull request #2463 from Nathon2Y/feat/KeyboardShortCut
Committer 代强
View all properties for this run ↗︎

Test results
Tests that failed  Failures 11
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 11
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 253
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.
View all changes introduced in this branch ↗︎

Tests for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants