-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
v3 TreeView #6020
v3 TreeView #6020
Changes from all commits
a10cc8e
870767c
d392e1b
4eab1d3
383f2c3
70e9327
a3ec22e
a939309
1c987d5
3a415eb
9b582b3
61e3d0f
7d6bbf7
21ea542
4b6f40b
57c5277
8b6c889
5e7a086
b45ea90
98c32e0
b336725
8ab0ffb
bfe77b5
8314c41
5105862
3e289b4
accf926
51655dc
bb06387
5d67f35
1e6430f
d82a7fd
d0fe8a1
35fbda1
746af85
9371403
a24c7a4
d8887f7
336e5c9
21c6444
6358462
ddbbb10
72197da
cb264a1
0e3fe69
d3070bc
7cd91a6
e896bb9
85d0f58
6b6492f
896ad4c
c0e38b8
7213dfe
6dd23aa
77ac56a
503c6e3
3882ad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"hasActionAnnouncement": "row has action", | ||
"hasLinkAnnouncement": "row has link: {link}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"hasActionAnnouncement": "row has action", | ||
"hasLinkAnnouncement": "row has link: {link}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,13 +308,12 @@ function ActionGroupItem<T>({item, state, isDisabled, isEmphasized, staticColor, | |
text: { | ||
id: hideButtonText ? textId : null, | ||
isHidden: hideButtonText | ||
}, | ||
icon: { | ||
UNSAFE_className: hideButtonText ? classNames(styles, 'spectrum-ActionGroup-itemIcon') : null | ||
} | ||
}}> | ||
<ActionButton | ||
ref={ref} | ||
// @ts-ignore (private) | ||
hideButtonText={hideButtonText} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. womps :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeaaaah pretty annoying that I had to do this, open to any alternative ideas |
||
UNSAFE_className={ | ||
classNames( | ||
styles, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {CheckboxContext, useContextProps} from 'react-aria-components'; | ||
import {CheckboxGroupContext} from './context'; | ||
import CheckmarkSmall from '@spectrum-icons/ui/CheckmarkSmall'; | ||
import {classNames, useFocusableRef, useStyleProps} from '@react-spectrum/utils'; | ||
|
@@ -27,6 +28,10 @@ import {useToggleState} from '@react-stately/toggle'; | |
|
||
function Checkbox(props: SpectrumCheckboxProps, ref: FocusableRef<HTMLLabelElement>) { | ||
let originalProps = props; | ||
let inputRef = useRef<HTMLInputElement>(null); | ||
let domRef = useFocusableRef(ref, inputRef); | ||
|
||
[props, domRef] = useContextProps(props, domRef, CheckboxContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RSP Checkbox need to be able to get the props from the RAC context setup by RAC Tree. Eventually be a moot point when we convert v3 to use RAC completely. |
||
props = useProviderProps(props); | ||
props = useFormProps(props); | ||
let { | ||
|
@@ -38,9 +43,6 @@ function Checkbox(props: SpectrumCheckboxProps, ref: FocusableRef<HTMLLabelEleme | |
} = props; | ||
let {styleProps} = useStyleProps(otherProps); | ||
|
||
let inputRef = useRef<HTMLInputElement>(null); | ||
let domRef = useFocusableRef(ref, inputRef); | ||
|
||
// Swap hooks depending on whether this checkbox is inside a CheckboxGroup. | ||
// This is a bit unorthodox. Typically, hooks cannot be called in a conditional, | ||
// but since the checkbox won't move in and out of a group, it should be safe. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {ActionGroup, Item} from '@react-spectrum/actiongroup'; | ||
import {ActionMenu} from '@react-spectrum/menu'; | ||
import Add from '@spectrum-icons/workflow/Add'; | ||
import Delete from '@spectrum-icons/workflow/Delete'; | ||
import Edit from '@spectrum-icons/workflow/Edit'; | ||
import FileTxt from '@spectrum-icons/workflow/FileTxt'; | ||
import Folder from '@spectrum-icons/workflow/Folder'; | ||
import React from 'react'; | ||
import {Text} from '@react-spectrum/text'; | ||
import {TreeView, TreeViewItem} from '../src'; | ||
|
||
export default { | ||
title: 'TreeView' | ||
}; | ||
|
||
function TestTree(props) { | ||
return ( | ||
<div style={{width: '300px', height: '800px'}}> | ||
<TreeView {...props} disabledKeys={['projects-1']} defaultExpandedKeys={['Photos', 'projects', 'projects-1']} aria-label="test static tree"> | ||
<TreeViewItem href="https://adobe.com/" id="Photos" textValue="Photos"> | ||
<Text>Photos</Text> | ||
<Folder /> | ||
<ActionGroup> | ||
<Item key="edit"> | ||
<Edit /> | ||
<Text>Edit</Text> | ||
</Item> | ||
<Item key="delete"> | ||
<Delete /> | ||
<Text>Delete</Text> | ||
</Item> | ||
</ActionGroup> | ||
</TreeViewItem> | ||
<TreeViewItem id="projects" textValue="Projects"> | ||
<Text>Projects</Text> | ||
<Folder /> | ||
<ActionMenu> | ||
<Item key="add"> | ||
<Add /> | ||
<Text>Add</Text> | ||
</Item> | ||
<Item key="delete"> | ||
<Delete /> | ||
<Text>Delete</Text> | ||
</Item> | ||
</ActionMenu> | ||
<TreeViewItem id="projects-1" textValue="Projects-1"> | ||
<Text>Projects-1</Text> | ||
<Folder /> | ||
<ActionGroup> | ||
<Item key="edit"> | ||
<Edit /> | ||
<Text>Edit</Text> | ||
</Item> | ||
<Item key="delete"> | ||
<Delete /> | ||
<Text>Delete</Text> | ||
</Item> | ||
</ActionGroup> | ||
<TreeViewItem id="projects-1A" textValue="Projects-1A"> | ||
<Text>Projects-1A</Text> | ||
<FileTxt /> | ||
<ActionMenu> | ||
<Item key="add"> | ||
<Add /> | ||
<Text>Add</Text> | ||
</Item> | ||
<Item key="delete"> | ||
<Delete /> | ||
<Text>Delete</Text> | ||
</Item> | ||
</ActionMenu> | ||
</TreeViewItem> | ||
</TreeViewItem> | ||
<TreeViewItem id="projects-2" textValue="Projects-2"> | ||
<Text>Projects-2</Text> | ||
<FileTxt /> | ||
<ActionGroup> | ||
<Item key="edit"> | ||
<Edit /> | ||
<Text>Edit</Text> | ||
</Item> | ||
<Item key="delete"> | ||
<Delete /> | ||
<Text>Delete</Text> | ||
</Item> | ||
</ActionGroup> | ||
</TreeViewItem> | ||
<TreeViewItem id="projects-3" textValue="Projects-3"> | ||
<Text>Projects-3</Text> | ||
<FileTxt /> | ||
</TreeViewItem> | ||
</TreeViewItem> | ||
</TreeView> | ||
</div> | ||
); | ||
} | ||
|
||
export const Default = () => ( | ||
<TestTree /> | ||
); | ||
|
||
export const SelectionMode = () => ( | ||
<TestTree selectionMode="multiple" /> | ||
); | ||
|
||
export const DisabledBehaviorAll = () => ( | ||
<TestTree disabledBehavior="all" selectionMode="multiple" /> | ||
); | ||
|
||
export const HiglightSelectionWithDisabledBehaviorAll = () => ( | ||
<TestTree selectionStyle="highlight" selectionMode="multiple" disabledBehavior="all" /> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to ActionGroup and ActionButton (and related css) is to avoid having
icon
slot provided classes provided from a parent (like TreeRow) from affecting the Icon rendered by the ActionButton. To do this, we clearSlots within ActionButton to stopicon
slot props from propagating down but still preserve the text props passed down via slots forhideButtonText
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did we avoid this problem in ListView?