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

LG-3301 | LG-3357: side nav style issues #2265

Merged
merged 7 commits into from
Mar 20, 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
9 changes: 9 additions & 0 deletions .changeset/long-sheep-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@leafygreen-ui/side-nav': patch
---

`SideNavItem` previously relied on parent context for `list-style`. Now, it is reset on each individual `SideNavItem`
[LG-3301](https://jira.mongodb.org/browse/LG-3301)

`SideNavGroupCollapsed` had a bug on initial render due to shallow dependency check. Now, when `initialCollapsed=false`, content will properly display on initial render
[LG-3357](https://jira.mongodb.org/browse/LG-3357)
11 changes: 10 additions & 1 deletion packages/side-nav/src/SideNavGroup/SideNavGroup.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import {
cleanup,
fireEvent,
render,
screen,
waitFor,
} from '@testing-library/react';

import Icon from '@leafygreen-ui/icon';

Expand Down Expand Up @@ -151,6 +157,9 @@ describe('packages/side-nav', () => {
test('the content appears on the page by default', () => {
const childContent = screen.getByTestId(sideNavLink);
expect(childContent).toBeInTheDocument();
waitFor(() => {
expect(childContent).toBeVisible();
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { Transition, TransitionStatus } from 'react-transition-group';

import { css, cx } from '@leafygreen-ui/emotion';
Expand Down Expand Up @@ -46,21 +46,27 @@ export function SideNavGroupCollapsed({
const { width, theme, darkMode } = useSideNavContext();
const { usingKeyboard } = useUsingKeyboardContext();

const [ulHeight, setUlHeight] = useState(0);

const menuId = useIdAllocator({ prefix: 'menu' });

const nodeRef = React.useRef(null);
const ulRef = React.useRef<HTMLUListElement>(null);

const ulRef = useCallback((node: HTMLUListElement) => {
if (node !== null) {
shaneeza marked this conversation as resolved.
Show resolved Hide resolved
setUlHeight(node.getBoundingClientRect().height);
}
}, []);

// compute the entered ul wrapper styles based on the ul height
useEffect(() => {
const ulHeight = ulRef?.current?.getBoundingClientRect().height ?? 0;
transitionStyles['entered'] = css`
opacity: 1;
max-height: ${ulHeight + 1}px; // +1 for border
border-bottom: 1px solid
${darkMode ? palette.gray.dark1 : palette.gray.light2};
`;
}, [open, ulRef, darkMode]);
}, [open, ulHeight, darkMode]);

return (
<>
Expand Down
1 change: 1 addition & 0 deletions packages/side-nav/src/SideNavItem/SideNavItem.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const sideNavItemClassName = createUniqueClassName('side-nav-item');

export const liStyle = css`
width: 100%;
list-style: none;
`;

// container styles
Expand Down
Loading