Skip to content

Commit

Permalink
LG-3301 | LG-3357: side nav style issues (#2265)
Browse files Browse the repository at this point in the history
* SideNavItem list-style

* Fix initialCollapsed={false} for SideNavGroupCollapsed

* SideNav changeset

* Use callback ref
  • Loading branch information
stephl3 authored Mar 20, 2024
1 parent 223666e commit f1a57ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
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) {
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

0 comments on commit f1a57ed

Please sign in to comment.