Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `9.6.0`.
- Changed `EuiNavDrawer` to close on any list item click ([#1770](https://github.com/elastic/eui/pull/1770))

## [`9.6.0`](https://github.com/elastic/eui/tree/v9.6.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,3 @@ exports[`EuiListGroupItem throws an warning if both iconType and icon are provid
</span>
</li>
`;

exports[`EuiListGroupItem throws an warning if both onClick and href are provided but still renders 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
>
<a
class="euiListGroupItem__button"
href="#"
>
<span
class="euiListGroupItem__label"
title=""
/>
</a>
</li>
`;
9 changes: 4 additions & 5 deletions src/components/list_group/list_group_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ export const EuiListGroupItem = ({

if (href && !isDisabled) {
itemContent = (
<a href={href} className="euiListGroupItem__button" {...rest}>
<a href={href} className="euiListGroupItem__button" onClick={onClick ? onClick : null} {...rest}>
{iconNode}
{labelContent}
</a>
);

if (onClick) {
console.warn('Both `href` and `onClick` were passed to EuiListGroupItem but only one can exist. The `href` was used.');
}
} else if ((href && isDisabled) || onClick) {
itemContent = (
<button
Expand Down Expand Up @@ -204,6 +200,9 @@ EuiListGroupItem.propTypes = {
alwaysShow: PropTypes.bool,
}),

/**
* Make the list item label a button if no href is provided
*/
onClick: PropTypes.func,

/**
Expand Down
12 changes: 0 additions & 12 deletions src/components/list_group/list_group_item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ describe('EuiListGroupItem', () => {
console.warn = oldConsoleError;
});

test('if both onClick and href are provided but still renders', () => {
const component = render(
<EuiListGroupItem label="" onClick={() => {}} href="#" />
);

expect(consoleStub).toBeCalled();
expect(consoleStub.mock.calls[0][0]).toMatch(
'`href` and `onClick` were passed'
);
expect(component).toMatchSnapshot();
});

test('if both iconType and icon are provided but still renders', () => {
const component = render(
<EuiListGroupItem label="" iconType="empty" icon={<span/>} />
Expand Down
1 change: 1 addition & 0 deletions src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class EuiNavDrawer extends Component {
const item = React.cloneElement(child, {
flyoutMenuButtonClick: this.expandFlyout,
showToolTips: this.state.toolTipsEnabled && showToolTips,
drawerItemClick: this.closeBoth,
});
return item;
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/components/nav_drawer/nav_drawer_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classNames from 'classnames';
import { EuiListGroup } from '../list_group/list_group';
import { toInitials } from '../../services';

export const EuiNavDrawerGroup = ({ className, listItems, flyoutMenuButtonClick, ...rest }) => {
export const EuiNavDrawerGroup = ({ className, listItems, flyoutMenuButtonClick, drawerItemClick, ...rest }) => {
const classes = classNames(
'euiNavDrawerGroup',
className
Expand All @@ -21,6 +21,9 @@ export const EuiNavDrawerGroup = ({ className, listItems, flyoutMenuButtonClick,
const items = [...flyoutMenu.listItems];
const title = `${flyoutMenu.title}`;
itemProps.onClick = () => flyoutMenuButtonClick(items, title);
// If not a flyout, close the nav drawer and flyout on any list item click
} else if (drawerItemClick) {
itemProps.onClick = () => drawerItemClick();
}

// Make some declarations of props for the side nav implementation
Expand Down Expand Up @@ -61,4 +64,9 @@ EuiNavDrawerGroup.propTypes = {
* of the flyout menu button click
*/
flyoutMenuButtonClick: PropTypes.func,
/**
* For items that don't open flyouts, it is required to pass a function for
* handling of the drawer item click to collapse the drawer
*/
drawerItemClick: PropTypes.func,
};