Skip to content

Commit 5fcfd47

Browse files
committed
detached styles
1 parent e9e4bf2 commit 5fcfd47

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const rowBackgroundColor = {
150150
}
151151
} as const;
152152

153-
const treeRow = style<TreeRowRenderProps>({
153+
const treeRow = style({
154154
position: 'relative',
155155
display: 'flex',
156156
height: 40,
@@ -159,6 +159,9 @@ const treeRow = style<TreeRowRenderProps>({
159159
boxSizing: 'border-box',
160160
font: 'ui',
161161
color: 'body',
162+
borderRadius: { // odd behaviour, if this is the last property, then bottom right isn't rounded
163+
isDetached: 'default'
164+
},
162165
outlineStyle: 'none',
163166
cursor: {
164167
default: 'default',
@@ -219,6 +222,17 @@ const treeContent = style({
219222
overflow: 'hidden'
220223
});
221224

225+
const cellFocus = {
226+
outlineStyle: {
227+
default: 'none',
228+
isFocusVisible: 'solid'
229+
},
230+
outlineOffset: -2,
231+
outlineWidth: 2,
232+
outlineColor: 'focus-ring',
233+
borderRadius: '[6px]'
234+
} as const;
235+
222236
export const TreeViewItem = <T extends object>(props: TreeViewItemProps<T>) => {
223237
let {
224238
children,
@@ -230,7 +244,7 @@ export const TreeViewItem = <T extends object>(props: TreeViewItemProps<T>) => {
230244
let content;
231245
let nestedRows;
232246
let {renderer} = useTreeRendererContext();
233-
// let {isDetached} = useContext(InternalTreeContext);
247+
let {isDetached} = useContext(InternalTreeContext);
234248
// TODO alternative api is that we have a separate prop for the TreeItems contents and expect the child to then be
235249
// a nested tree item
236250

@@ -262,10 +276,11 @@ export const TreeViewItem = <T extends object>(props: TreeViewItemProps<T>) => {
262276
{...props}
263277
className={renderProps => treeRow({
264278
...renderProps,
279+
isDetached,
265280
isLink: !!href
266-
}) + (renderProps.isFocusVisible && ' ' + raw('&:before { content: ""; display: inline-block; position: sticky; inset-inline-start: 0; width: 3px; height: 100%; margin-inline-end: -3px; margin-block-end: 1px; z-index: 3; background-color: var(--rowFocusIndicatorColor)'))}>
281+
}) + (renderProps.isFocusVisible && !isDetached && ' ' + raw('&:before { content: ""; display: inline-block; position: sticky; inset-inline-start: 0; width: 3px; height: 100%; margin-inline-end: -3px; margin-block-end: 1px; z-index: 3; background-color: var(--rowFocusIndicatorColor)'))}>
267282
<UNSTABLE_TreeItemContent>
268-
{({isExpanded, hasChildRows, selectionMode, selectionBehavior, isDisabled}) => (
283+
{({isExpanded, hasChildRows, selectionMode, selectionBehavior, isDisabled, isFocusVisible}) => (
269284
<div className={treeCellGrid({isDisabled})}>
270285
{selectionMode !== 'none' && selectionBehavior === 'toggle' && (
271286
// TODO: add transition?
@@ -289,6 +304,7 @@ export const TreeViewItem = <T extends object>(props: TreeViewItemProps<T>) => {
289304
]}>
290305
{content}
291306
</Provider>
307+
{isFocusVisible && isDetached && <div role="presentation" className={style({...cellFocus, position: 'absolute', inset: 0})({isFocusVisible: true})} />}
292308
</div>
293309
)}
294310
</UNSTABLE_TreeItemContent>

0 commit comments

Comments
 (0)