Skip to content

Commit 279b482

Browse files
committed
fix(treeview): focused value state
1 parent 3142ee9 commit 279b482

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

packages/machines/tree-view/src/tree-view.machine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export const machine = createMachine<TreeViewSchema>({
5151
},
5252
})),
5353
focusedValue: bindable(() => ({
54-
defaultValue: prop("focusedValue"),
54+
defaultValue: prop("defaultFocusedValue") || null,
55+
value: prop("focusedValue"),
5556
onChange(value) {
5657
prop("onFocusChange")?.({ focusedValue: value })
5758
},

packages/machines/tree-view/src/tree-view.props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const props = createProps<TreeViewProps>()([
88
"dir",
99
"expandedValue",
1010
"expandOnClick",
11+
"defaultFocusedValue",
1112
"focusedValue",
1213
"getRootNode",
1314
"id",

packages/machines/tree-view/src/tree-view.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export interface TreeViewProps<T = any> extends DirectionProperty, CommonPropert
111111
* The controlled checked node value
112112
*/
113113
checkedValue?: string[] | undefined
114+
/**
115+
* The initial focused node value when rendered.
116+
* Use when you don't need to control the focused node value.
117+
*/
118+
defaultFocusedValue?: string | null | undefined
114119
/**
115120
* The value of the focused node
116121
*/

0 commit comments

Comments
 (0)