Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit b85c3ab

Browse files
authored
Adding up & down key navigation (accessibility) feature for Tree component (#1219)
* Adding up & down key accessibility feature for Tree component * Updating changelog
1 parent f19bf99 commit b85c3ab

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2121
- Fix overflowing focus outline for `Grid` items for Teams theme @Bugaa92 ([#1195](https://github.com/stardust-ui/react/pull/1195))
2222
- Fix routing for accessibility documentation @sophieH29 ([#1208](https://github.com/stardust-ui/react/pull/1208))
2323
- Fix `content` prop type in `Dialog` @layershifter ([#1212](https://github.com/stardust-ui/react/pull/1212))
24+
- Add `keyboard` up & down key controls for the `Tree` component @priyankar205 ([#1219]https://github.com/stardust-ui/react/pull/1219)
2425

2526
### Features
2627
- Add `Embed` and `Video` components @stuartlong ([#1108](https://github.com/stardust-ui/react/pull/1108))

packages/react/src/components/Tree/Tree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../../lib'
1616
import { ShorthandValue, ShorthandRenderFunction, ReactProps } from '../../types'
1717
import { Accessibility } from '../../lib/accessibility/types'
18-
import { defaultBehavior } from '../../lib/accessibility'
18+
import { treeBehavior } from '../../lib/accessibility'
1919

2020
export interface TreeSlotClassNames {
2121
item: string
@@ -88,7 +88,7 @@ class Tree extends AutoControlledComponent<ReactProps<TreeProps>, TreeState> {
8888

8989
public static defaultProps = {
9090
as: 'ul',
91-
accessibility: defaultBehavior,
91+
accessibility: treeBehavior,
9292
}
9393

9494
static autoControlledProps = ['activeIndex']

packages/react/src/components/Tree/TreeItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class TreeItem extends UIComponent<ReactProps<TreeItemProps>> {
127127
{open &&
128128
Tree.create(items, {
129129
defaultProps: {
130+
accessibility: defaultBehavior,
130131
className: TreeItem.slotClassNames.subtree,
131132
exclusive,
132133
renderItemTitle,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Accessibility, FocusZoneMode } from '../../types'
2+
import { FocusZoneDirection } from '../../FocusZone'
3+
4+
/**
5+
* @specification
6+
* Embeds FocusZone into component allowing circular arrow key navigation through the children of the component.
7+
*/
8+
const treeBehavior: Accessibility = (props: any) => ({
9+
attributes: {
10+
root: {},
11+
},
12+
focusZone: {
13+
mode: FocusZoneMode.Embed,
14+
props: {
15+
isCircularNavigation: true,
16+
preventDefaultWhenHandled: true,
17+
direction: FocusZoneDirection.vertical,
18+
},
19+
},
20+
})
21+
22+
export default treeBehavior

packages/react/src/lib/accessibility/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export { default as popupAutoFocusBehavior } from './Behaviors/Popup/popupAutoFo
3030
export { default as chatBehavior } from './Behaviors/Chat/chatBehavior'
3131
export { default as chatMessageBehavior } from './Behaviors/Chat/chatMessageBehavior'
3232
export { default as gridBehavior } from './Behaviors/Grid/gridBehavior'
33+
export { default as treeBehavior } from './Behaviors/Tree/treeBehavior'
3334
export { default as treeTitleBehavior } from './Behaviors/Tree/treeTitleBehavior'
3435
export { default as dialogBehavior } from './Behaviors/Dialog/dialogBehavior'
3536
export { default as statusBehavior } from './Behaviors/Status/statusBehavior'

packages/react/test/specs/behaviors/behavior-test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
toggleButtonBehavior,
3232
toolbarBehavior,
3333
toolbarButtonBehavior,
34+
treeBehavior,
3435
treeTitleBehavior,
3536
gridBehavior,
3637
statusBehavior,
@@ -70,6 +71,7 @@ testHelper.addBehavior('toolbarBehavior', toolbarBehavior)
7071
testHelper.addBehavior('toggleButtonBehavior', toggleButtonBehavior)
7172
testHelper.addBehavior('toolbarButtonBehavior', toolbarButtonBehavior)
7273
testHelper.addBehavior('treeTitleBehavior', treeTitleBehavior)
74+
testHelper.addBehavior('treeBehavior', treeBehavior)
7375
testHelper.addBehavior('gridBehavior', gridBehavior)
7476
testHelper.addBehavior('dialogBehavior', dialogBehavior)
7577
testHelper.addBehavior('statusBehavior', statusBehavior)

0 commit comments

Comments
 (0)