Skip to content

Commit

Permalink
feat: close header side nav on navigation (#3826)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectordavis authored Sep 25, 2023
1 parent 2d7a364 commit e65bbc8
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
uses: actions/setup-node@v1
if: steps.changes.outputs.react == 'true'
with:
node-version: '16.x'
node-version: '20.x'

- name: Run cli command to create test app
if: steps.changes.outputs.react == 'true'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ibm-ai-applications",
"engines": {
"node": "12.x || 14.x || 16.x || 18.x"
"node": "12.x || 14.x || 16.x || 18.x || 20.x"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "carbon-addons-iot-react",
"engines": {
"node": "12.x || 14.x || 16.x || 18.x"
"node": "12.x || 14.x || 16.x || 18.x || 20.x"
},
"browser": "es/index.js",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const Header = ({
data-testid={`${testId}-menu-button`}
aria-label={isSideNavExpanded ? mergedI18n.closeMenu : mergedI18n.openMenu}
onClick={onClickSideNavExpand}
isActive={isSideNavExpanded}
/>
)}
<HeaderName
Expand Down
548 changes: 301 additions & 247 deletions packages/react/src/components/SuiteHeader/SuiteHeader.jsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export const HeaderWithSideNav = () => {
appName="Application Name"
userDisplayName="Admin User"
username="adminuser"
closeSideNavOnNavigation={boolean('Close side nav on navigation', false)}
routes={routes}
applications={applications}
sideNavProps={{
Expand Down
106 changes: 106 additions & 0 deletions packages/react/src/components/SuiteHeader/SuiteHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1341,4 +1341,110 @@ describe('SuiteHeader', () => {

expect(screen.queryByRole('button', { name: 'Open Menu' })).toBeNull();
});

it('checks if close icon appears when menu is open', async () => {
render(
<SuiteHeader
{...commonProps}
sideNavProps={{
links: [
{
isEnabled: true,
icon: Chip,
metaData: {
label: 'Devices',
href: 'https://google.com',
element: 'a',
target: '_blank',
},
linkContent: 'Devices',
},
],
}}
/>
);
const menuButton = screen.getByRole('button', { name: 'Open menu' });
// Check if menu button is rendered
expect(menuButton).toBeInTheDocument();
// Click menu button
await userEvent.click(menuButton);
// Check if menu button was removed and close button appeared
expect(screen.queryByRole('button', { name: 'Open menu' })).toBeNull();
expect(screen.getByRole('button', { name: 'Close menu' })).toBeInTheDocument();
});

it('checks if side nav closes when clicking an item', async () => {
render(
<SuiteHeader
suiteName="Application Suite"
appName="Application Name"
userDisplayName="Admin User"
username="adminuser"
routes={{
profile: 'https://www.ibm.com',
navigator: 'https://www.ibm.com',
admin: 'https://www.ibm.com',
logout: 'https://www.ibm.com',
logoutInactivity: 'https://www.ibm.com',
whatsNew: 'https://www.ibm.com',
gettingStarted: 'https://www.ibm.com',
documentation: 'https://www.ibm.com',
requestEnhancement: 'https://www.ibm.com',
support: 'https://www.ibm.com',
about: 'https://www.ibm.com',
workspaceId: 'workspace1',
domain: '',
}}
applications={[
{
id: 'monitor',
name: 'Monitor',
href: 'https://www.ibm.com',
},
{
id: 'health',
name: 'Health',
href: 'https://google.com',
isExternal: true,
},
]}
closeSideNavOnNavigation
sideNavProps={{
links: [
{
isEnabled: true,
isActive: true,
icon: Chip,
metaData: {
label: 'Mobile',
},
linkContent: 'Mobile',
},
],
}}
/>
);
const menuButton = screen.getByRole('button', { name: 'Open menu' });
// Check if menu button is rendered
expect(menuButton).toBeInTheDocument();
// Click menu button
userEvent.click(menuButton);
// Check if menu button was removed and close button appeared
expect(screen.queryByRole('button', { name: 'Open menu' })).toBeNull();
expect(screen.getByRole('button', { name: 'Close menu' })).toBeInTheDocument();
// Check if nav bar is open
const sideNav = screen.getByTestId('suite-header-side-nav');
expect(sideNav).toHaveClass('bx--side-nav--expanded');

// Get first nav item and click it
const item = within(sideNav).getByTestId('suite-header-side-nav-link-0');
fireEvent.click(item);
// Take focus away from item
fireEvent.blur(item);
// Check if side nav closed
expect(sideNav).not.toHaveClass('bx--side-nav--expanded');
// Check if close menu button disappeared and open menu (hamburger) button is in the document
expect(screen.queryByRole('button', { name: 'Close menu' })).toBeNull();
expect(screen.getByRole('button', { name: 'Open menu' })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11874,6 +11874,7 @@ Map {
"appName": null,
"applications": null,
"className": null,
"closeSideNavOnNavigation": false,
"customActionItems": Array [],
"customApplications": Array [],
"customHelpLinks": Array [],
Expand Down Expand Up @@ -11975,6 +11976,9 @@ Map {
"className": Object {
"type": "string",
},
"closeSideNavOnNavigation": Object {
"type": "bool",
},
"customActionItems": Object {
"args": Array [
Object {
Expand Down

0 comments on commit e65bbc8

Please sign in to comment.