Skip to content

Commit 144a538

Browse files
authored
chore: update disabledBehavior style for S2 TreeView (adobe#9472)
* chore: update disabledBehavior style in S2 TreeView * add chromatic story * fix isDisabled case * add tests * fix tests
1 parent bed17e4 commit 144a538

4 files changed

Lines changed: 513 additions & 247 deletions

File tree

packages/@react-spectrum/s2/chromatic/TreeView.stories.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function TreeExample(props: TreeViewProps<any>): ReactElement {
3737
disabledKeys={['projects-1']}
3838
aria-label="test static tree"
3939
expandedKeys={['projects']}>
40-
4140
<TreeViewItem id="Photos" textValue="Photos">
4241
<TreeViewItemContent>
4342
<Text>Photos</Text>
@@ -152,6 +151,15 @@ export const TreeSelection: StoryObj<typeof TreeExample> = {
152151
}
153152
};
154153

154+
export const TreeDisableSelection: StoryObj<typeof TreeExample> = {
155+
...TreeStatic,
156+
args: {
157+
selectionMode: 'multiple',
158+
defaultSelectedKeys: ['projects-2', 'projects-3'],
159+
disabledBehavior: 'selection'
160+
}
161+
};
162+
155163
interface TreeViewItemType {
156164
id: string,
157165
name: string,

packages/@react-spectrum/s2/src/TreeView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ const treeCheckbox = style({
217217
gridArea: 'checkbox',
218218
marginStart: 12,
219219
marginEnd: 0,
220-
paddingEnd: 0
220+
paddingEnd: 0,
221+
visibility: {
222+
default: 'visible',
223+
isDisabled: 'hidden'
224+
}
221225
});
222226

223227
const treeIcon = style({
@@ -302,7 +306,7 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
302306
<div className={treeCellGrid({isDisabled, isNextSelected, isSelected, isFirst, isNextFocused})}>
303307
{selectionMode !== 'none' && selectionBehavior === 'toggle' && (
304308
// TODO: add transition?
305-
<div className={treeCheckbox}>
309+
<div className={treeCheckbox({isDisabled: isDisabled || !state.selectionManager.canSelectItem(id) || state.disabledKeys.has(id)})}>
306310
<Checkbox slot="selection" />
307311
</div>
308312
)}
@@ -319,8 +323,8 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
319323
render: centerBaseline({slot: 'icon', styles: treeIcon}),
320324
styles: style({size: fontRelative(20), flexShrink: 0})
321325
}],
322-
[ActionButtonGroupContext, {styles: treeActions}],
323-
[ActionMenuContext, {styles: treeActionMenu, isQuiet: true}]
326+
[ActionButtonGroupContext, {styles: treeActions, isDisabled}],
327+
[ActionMenuContext, {styles: treeActionMenu, isQuiet: true, isDisabled}]
324328
]}>
325329
{typeof children === 'string' ? <Text>{children}</Text> : children}
326330
</Provider>

packages/@react-spectrum/s2/test/Tree.test.tsx

Lines changed: 0 additions & 242 deletions
This file was deleted.

0 commit comments

Comments
 (0)