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/cascader search #2030

Merged
merged 3 commits into from Feb 6, 2024
Merged

Fix/cascader search #2030

merged 3 commits into from Feb 6, 2024

Conversation

YyumeiZhang
Copy link
Collaborator

@YyumeiZhang YyumeiZhang commented Jan 19, 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

  • Cascader 在搜索内容为英文逗号时选项面板显示全部选项
    image

问题原因,使用了 join引入了多余的 , 逗号

var a = [1,2,3]
a.join('')  // 123  ,应该这么写
a.join()   // 1,2,3   不应该这么写

Changelog

🇨🇳 Chinese

  • Fix: 修复 Cascader 在搜索内容为英文逗号时选项面板显示全部选项问题
  • Fix: 修复多选,showClear 的 Cascader 在点击清除按钮后,选项面板没有从搜索状态切换到普通状态问题

🇺🇸 English

  • Fix: Fixed the issue where Cascader's options panel displays all options when search content is English commas
  • Fix: Fixed the problem of multi-selection and showClear's Cascader. After clicking the clear button, the options panel did not switch from the search state to the normal state.

Checklist

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

Other

  • Skip Changelog

Additional information

Copy link

codesandbox-ci bot commented Jan 19, 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 6771a3f:

Sandbox Source
pr-story Configuration
Semi Design: Simple Story Configuration

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (c81cf78) 87.44% compared to head (610891e) 87.40%.
Report is 19 commits behind head on main.

❗ Current head 610891e differs from pull request most recent head 6771a3f. Consider uploading reports for the commit 6771a3f to get more accurate results

Files Patch % Lines
packages/semi-ui/input/textarea.tsx 80.95% 4 Missing ⚠️
packages/semi-foundation/cascader/util.ts 90.90% 1 Missing ⚠️
...es/semi-foundation/image/previewInnerFoundation.ts 66.66% 1 Missing ⚠️
packages/semi-ui/image/previewInner.tsx 50.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2030      +/-   ##
==========================================
- Coverage   87.44%   87.40%   -0.05%     
==========================================
  Files         437      437              
  Lines       25664    25667       +3     
  Branches     6504     6502       -2     
==========================================
- Hits        22441    22433       -8     
- Misses       3223     3234      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cypress bot commented Jan 19, 2024

Passing run #2226 ↗︎

0 219 10 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge 6771a3f into 1fe3733...
Project: semi-design Commit: 610891eb27 ℹ️
Status: Passed Duration: 08:26 💡
Started: Jan 29, 2024 10:04 AM Ended: Jan 29, 2024 10:12 AM

Review all test suite changes for PR #2030 ↗︎

@@ -908,7 +908,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
if (_notExist) {
return false;
}
const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join();
const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join('');
return filter(sugInput, data, filterTreeNode, false, filteredPath);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

搜索内容为英文逗号时,匹配全量数据的问题时因为此处拼接级连数据时,用了数组的 join(),引入了多余的英文逗号,导致选项都满足筛选条件

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

此处修改的风险问题:在 filterTreeNode 的第二个参数返回值有变化
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

参数返回值改变,这个不行

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

已修改。 原来 tree/treeSelect/Cascader公用 tree/treeUtils.tsx中的 filter,为修复 cascader 中搜索英文逗号匹配全量数据的问题,同时保证 filterTreeNode 中对外透传的 treeNodeString 不变。另外为了便于理解,将 cascader 的 filter 单独拆分出在 foundation 的 cascader/utils.tsx中

@@ -932,6 +932,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
const isControlled = this._isControlledComponent();
const newState: Partial<BasicCascaderInnerData> = {};
if (multiple) {
newState.isSearching = false;
this._adapter.updateInputValue('');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

在点击清除按钮后,已选项和搜索数据都被清空, 应该将 isSearching 修改为 false,和单选的清空状态处理保持一致,否则会造成多选,搜素时,点击清空按钮,选项面板无法从搜索状态转为普通状态

const hasValue = selectedKeys.size;
const multipleWithHaveValue = multiple && checkedKeys.size;
return showClear && (hasValue || multipleWithHaveValue) && !disabled && (isOpen || isHovering);
return showClear && (inputValue || hasValue || multipleWithHaveValue) && !disabled && (isOpen || isHovering);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

设置了 showClear,在有已选项 或者 有搜索值时候,满足其他条件的情况下,都应该显示 清除按钮

@pointhalo pointhalo merged commit 0a34016 into main Feb 6, 2024
9 checks passed
@pointhalo pointhalo deleted the fix/cascader-search branch February 6, 2024 08:03
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.

None yet

3 participants