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

cascader can not filter correctly when a node has no children #2104

Closed
zd5043039119 opened this Issue Sep 5, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@zd5043039119
Contributor

zd5043039119 commented Sep 5, 2018

Version

1.4.1

Environment

Angular 6.1.3,Chrome 67.0.3396.87

Reproduction link

https://stackblitz.com/edit/ng-zorro-antd-start-mshvaz

Steps to reproduce

  1. 触发Cascader,并使焦点聚集在输入框
  2. 输入Test这个单词的任意结果

What is expected?

能出现高亮的Test选项

What is actually happening?

Not Found

Other?

@wendzhue wendzhue self-assigned this Sep 5, 2018

@wendzhue

This comment has been minimized.

Member

wendzhue commented Sep 5, 2018

@zd5043039119 Please provide the edit link, not just the demo.

@zd5043039119

This comment has been minimized.

Contributor

zd5043039119 commented Sep 6, 2018

@wendzhue Updated

@wendzhue

This comment has been minimized.

Member

wendzhue commented Sep 6, 2018

@zd5043039119 You didn't mark the node as isLeaf so it would treated as a non-leaf node, which means it shouldn't be able to dispatch a value at all.

@wendzhue wendzhue closed this Sep 6, 2018

@wendzhue

This comment has been minimized.

Member

wendzhue commented Sep 6, 2018

But it do have a problem. I would fix it for another issue.

@zd5043039119

This comment has been minimized.

Contributor

zd5043039119 commented Sep 6, 2018

@wendzhue i updated the reproduction link and mark the node as isLeaf, but get the same result, and i read the source code,

const loopParent = (node: CascaderOption, forceDisabled = false) => {
      const disabled = forceDisabled || node.disabled;
      path.push(node);
      node.children.forEach((sNode) => {
        if (!sNode.parent) { sNode.parent = node; } /** 搜索的同时建立 parent 连接,因为用户直接搜索的话是没有建立连接的,会提升从叶子节点回溯的难度 */
        if (!sNode.isLeaf) { loopParent(sNode, disabled); }
        if (sNode.isLeaf || !sNode.children) { loopChild(sNode, disabled); }
      });
      path.pop();
    };

node.children is empty and loopChild will never be executed, so filter will never be executed

@wendzhue

This comment has been minimized.

Member

wendzhue commented Sep 6, 2018

@zd5043039119 Yes that's a reason.

Since you have found the reason, are you interested in firing a pull request to fix this?

@zd5043039119

This comment has been minimized.

Contributor

zd5043039119 commented Sep 6, 2018

sure, i'll try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment