diff --git a/packages/components/src/tree-item/tree-item.styles.ts b/packages/components/src/tree-item/tree-item.styles.ts index 09574b3c..f2f05d78 100644 --- a/packages/components/src/tree-item/tree-item.styles.ts +++ b/packages/components/src/tree-item/tree-item.styles.ts @@ -44,6 +44,12 @@ import { heightNumber } from '../styles/index.js'; +/** + * Tree item expand collapse button size CSS Partial + * @public + */ +export const expandCollapseButtonSize = cssPartial`(((${baseHeightMultiplier} + ${density}) * 0.5 + 2) * ${designUnit})`; + const ltr = css` .expand-collapse-glyph { transform: rotate(0deg); @@ -51,7 +57,12 @@ const ltr = css` :host(.nested) .expand-collapse-button { left: var( --expand-collapse-button-nested-width, - calc(${heightNumber} * -1px) + calc( + ( + ${expandCollapseButtonSize} + + ((${baseHeightMultiplier} + ${density}) * 1.25) + ) * -1px + ) ); } :host([selected])::after { @@ -69,7 +80,12 @@ const rtl = css` :host(.nested) .expand-collapse-button { right: var( --expand-collapse-button-nested-width, - calc(${heightNumber} * -1px) + calc( + ( + ${expandCollapseButtonSize} + + ((${baseHeightMultiplier} + ${density}) * 1.25) + ) * -1px + ) ); } :host([selected])::after { @@ -80,12 +96,6 @@ const rtl = css` } `; -/** - * Tree item expand collapse button size CSS Partial - * @public - */ -export const expandCollapseButtonSize = cssPartial`((${baseHeightMultiplier} / 2) * ${designUnit}) + ((${designUnit} * ${density}) / 2)`; - const expandCollapseHoverBehavior = DesignToken.create( 'tree-item-expand-collapse-hover' ).withDefault((target: HTMLElement) => { @@ -132,7 +142,6 @@ export const treeItemStyles: FoundationElementTemplate< background: ${neutralFillStealthRest}; cursor: pointer; font-family: ${bodyFont}; - --expand-collapse-button-size: calc(${heightNumber} * 1px); --tree-item-nested-width: 0; } @@ -199,8 +208,8 @@ export const treeItemStyles: FoundationElementTemplate< border: none; outline: none; /* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */ - width: calc((${expandCollapseButtonSize} + (${designUnit} * 2)) * 1px); - height: calc((${expandCollapseButtonSize} + (${designUnit} * 2)) * 1px); + width: calc(${expandCollapseButtonSize} * 1px); + height: calc(${expandCollapseButtonSize} * 1px); padding: 0; display: flex; justify-content: center; @@ -261,7 +270,13 @@ export const treeItemStyles: FoundationElementTemplate< :host(.nested) .content-region { position: relative; - margin-inline-start: var(--expand-collapse-button-size); + /* Add left margin to collapse button size */ + margin-inline-start: calc( + ( + ${expandCollapseButtonSize} + + ((${baseHeightMultiplier} + ${density}) * 1.25) + ) * 1px + ); } :host(.nested) .expand-collapse-button { @@ -304,7 +319,12 @@ export const treeItemStyles: FoundationElementTemplate< ::slotted(${context.tagFor(TreeItem)}) { --tree-item-nested-width: 1em; - --expand-collapse-button-nested-width: calc(${heightNumber} * -1px); + --expand-collapse-button-nested-width: calc( + ( + ${expandCollapseButtonSize} + + ((${baseHeightMultiplier} + ${density}) * 1.25) + ) * -1px + ); } `.withBehaviors( new DirectionalStyleSheetBehavior(ltr, rtl), diff --git a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-chromium-linux.png b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-chromium-linux.png index a49d03d6..0b1add58 100644 Binary files a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-chromium-linux.png and b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-chromium-linux.png differ diff --git a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-firefox-linux.png b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-firefox-linux.png index 40b3de68..e405ebf7 100644 Binary files a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-firefox-linux.png and b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-firefox-linux.png differ diff --git a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-webkit-linux.png b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-webkit-linux.png index 67d69403..06f74ce0 100644 Binary files a/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-webkit-linux.png and b/packages/components/src/tree-view/tree-view.test.ts-snapshots/tree-view-default-webkit-linux.png differ diff --git a/packages/react-components/lib/TreeView.js b/packages/react-components/lib/TreeView.js index cf7b4a26..9ab6b224 100644 --- a/packages/react-components/lib/TreeView.js +++ b/packages/react-components/lib/TreeView.js @@ -2,7 +2,12 @@ import { jpTreeView, provideJupyterDesignSystem } from '@jupyter/web-components'; -import React, { forwardRef, useImperativeHandle, useRef } from 'react'; +import React, { + forwardRef, + useLayoutEffect, + useImperativeHandle, + useRef +} from 'react'; import { useProperties } from './react-utils.js'; provideJupyterDesignSystem().register(jpTreeView()); @@ -12,6 +17,12 @@ export const TreeView = forwardRef((props, forwardedRef) => { const { className, renderCollapsedNodes, currentSelected, ...filteredProps } = props; + useLayoutEffect(() => { + // Fix using private API to force refresh of nested flag on + // first level of tree items. + ref.current?.setItems(); + }, [ref.current]); + /** Properties - run whenever a property has changed */ useProperties(ref, 'currentSelected', props.currentSelected);