Skip to content
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

Fix treeview glitches #109

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions packages/components/src/tree-item/tree-item.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@ 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);
}
: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 {
Expand All @@ -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 {
Expand All @@ -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<Swatch>(
'tree-item-expand-collapse-hover'
).withDefault((target: HTMLElement) => {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion packages/react-components/lib/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -11,6 +16,12 @@ export const TreeView = forwardRef((props, forwardedRef) => {
const ref = useRef(null);
const { 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);

Expand Down
Loading