Skip to content

Commit c9942c1

Browse files
authored
feat: add search menu button to header (#474)
1 parent 432dbb5 commit c9942c1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/studio-header/HeaderBody.jsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { useIntl } from '@edx/frontend-platform/i18n';
34
import {
45
ActionRow,
56
Button,
67
Container,
8+
Icon,
9+
IconButton,
710
Nav,
811
Row,
912
} from '@openedx/paragon';
10-
import { Close, MenuIcon } from '@openedx/paragon/icons';
13+
import { Close, MenuIcon, Search } from '@openedx/paragon/icons';
1114

1215
import CourseLockUp from './CourseLockUp';
1316
import UserMenu from './UserMenu';
1417
import BrandNav from './BrandNav';
1518
import NavDropdownMenu from './NavDropdownMenu';
19+
import messages from './messages';
1620

1721
const HeaderBody = ({
1822
logo,
@@ -32,7 +36,10 @@ const HeaderBody = ({
3236
isHiddenMainMenu,
3337
mainMenuDropdowns,
3438
outlineLink,
39+
searchButtonAction,
3540
}) => {
41+
const intl = useIntl();
42+
3643
const renderBrandNav = (
3744
<BrandNav
3845
{...{
@@ -96,6 +103,16 @@ const HeaderBody = ({
96103
</>
97104
)}
98105
<ActionRow.Spacer />
106+
{searchButtonAction && (
107+
<Nav>
108+
<IconButton
109+
src={Search}
110+
iconAs={Icon}
111+
onClick={searchButtonAction}
112+
aria-label={intl.formatMessage(messages['header.label.search.nav'])}
113+
/>
114+
</Nav>
115+
)}
99116
<Nav>
100117
<UserMenu
101118
{...{
@@ -137,6 +154,7 @@ HeaderBody.propTypes = {
137154
})),
138155
})),
139156
outlineLink: PropTypes.string,
157+
searchButtonAction: PropTypes.func,
140158
};
141159

142160
HeaderBody.defaultProps = {
@@ -155,6 +173,7 @@ HeaderBody.defaultProps = {
155173
isHiddenMainMenu: false,
156174
mainMenuDropdowns: [],
157175
outlineLink: null,
176+
searchButtonAction: null,
158177
};
159178

160179
export default HeaderBody;

src/studio-header/StudioHeader.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ensureConfig([
1616
], 'Studio Header component');
1717

1818
const StudioHeader = ({
19-
number, org, title, isHiddenMainMenu, mainMenuDropdowns, outlineLink,
19+
number, org, title, isHiddenMainMenu, mainMenuDropdowns, outlineLink, searchButtonAction,
2020
}) => {
2121
const { authenticatedUser, config } = useContext(AppContext);
2222
const props = {
@@ -33,6 +33,7 @@ const StudioHeader = ({
3333
isHiddenMainMenu,
3434
mainMenuDropdowns,
3535
outlineLink,
36+
searchButtonAction,
3637
};
3738

3839
return (
@@ -62,6 +63,7 @@ StudioHeader.propTypes = {
6263
})),
6364
})),
6465
outlineLink: PropTypes.string,
66+
searchButtonAction: PropTypes.func,
6567
};
6668

6769
StudioHeader.defaultProps = {
@@ -70,6 +72,7 @@ StudioHeader.defaultProps = {
7072
isHiddenMainMenu: false,
7173
mainMenuDropdowns: [],
7274
outlineLink: null,
75+
searchButtonAction: null,
7376
};
7477

7578
export default StudioHeader;

src/studio-header/StudioHeader.test.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const props = {
6969
},
7070
],
7171
outlineLink: 'tEsTLInK',
72+
searchButtonAction: null,
7273
};
7374

7475
describe('Header', () => {
@@ -138,6 +139,20 @@ describe('Header', () => {
138139

139140
expect(desktopMenu).toBeNull();
140141
});
142+
143+
it('should show search button', async () => {
144+
const testProps = { ...props, searchButtonAction: () => undefined };
145+
const { getByRole } = render(<RootWrapper {...testProps} />);
146+
const searchButton = getByRole('button', { name: 'Search content' });
147+
148+
expect(searchButton).toBeVisible();
149+
});
150+
151+
it('should not show search button', async () => {
152+
const testProps = { ...props, searchButtonAction: null };
153+
const { queryByRole } = render(<RootWrapper {...testProps} />);
154+
expect(queryByRole('button', { name: 'Search content' })).not.toBeInTheDocument();
155+
});
141156
});
142157

143158
describe('mobile', () => {

src/studio-header/messages.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ const messages = defineMessages({
5151
defaultMessage: 'Back to course outline in Studio',
5252
description: 'The aria label for the link back to the Studio Course Outline',
5353
},
54+
'header.label.search.nav': {
55+
id: 'header.label.search.nav',
56+
defaultMessage: 'Search content',
57+
description: 'The aria label for the search content button nav',
58+
},
5459
});
5560

5661
export default messages;

0 commit comments

Comments
 (0)