You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LouisSung
changed the title
FeatureRequest(NzTree): Keyboard control for tree expand, collapse, and node focus
FeatureRequest(Component: Tree): Keyboard control for tree expand, collapse, and node focus
May 15, 2020
Thanks for your feedback, I will check it as soon as I can. All features of ng-zorro-antd are following the design of ant-design, please make sure ant-design has supported that or if you can implement it with template :)
I did implement it using template; however, it's quite tricky and inefficient (requires each tree to be hacked once).
For example, the NzTreeComponent doesn't expose its ElementRef and <input> thus requires @ViewChild() and querySelector() to get ones.
Seems like the Tree Component in Ant Design does not support keyboard control either : (
Is there any plan to add keyboard control or a11y to components like dropdown, menu, tree, etc. for either Ant Design or NG-ZORRO?
Or at least expose important things like the ElementRef and <input> of NzTree without changing the UI and the existing features _(;3
What problem does this feature solve?
Since NzTree is often used for files display and management, it's better to have keyboard control support like an IDE does.
I know the NzTree is now under refactoring, it might be a good chance to integrate the new features :D
I've also wrote an example @gist (core code), @repo (whole project), and @stackblitz (build failed...), which is highly inspired by Intellij
Demo
(Shift-)Tab
>Single Click
>Double Click
>*
>-
>+
>-
>→
>←
Features
Single Click
: focus tree nodeDouble Click
: toggle between collapsed and expanded (i.e.,+
&-
/Enter
)(Shift-)Tab
: switch between<input>
and<nz-tree>
Esc
: blurEnter
: toggle between collapsed and expanded (when!isLeaf
) (i.e., Double Click)↑ ↓
: select previous/next node←
: move to parent (whenisLeaf
or!isExpanded
) or collapse recursively (whenisExpanded
)→
: next node (i.e.,↓
) (whenisLeaf
orisExpanded
) or expand next level (i.e.,+
)*
: expand recursively+
: expand next level only-
: collapse recursivelyImplementation
<input>
inside<nz-tree>
first so thattreeFocuse()
can be used to focus treeInputRef and treeNodefocus
andblur
events totreeInputElement
to handleTab
andShift-Tab
cases (switch using keyboard rather than mouse clicking)(keydown)
,(nzClick)
, and(nzDblClick)
events directly on<nz-tree>
What does the proposed API look like?
focusedNode
for each NzTree rather than use the existingisSelected
to implement node focus.<input>
may be exposed for user to bind customize events onThe text was updated successfully, but these errors were encountered: