Skip to content

Commit

Permalink
feat(OverflowMenuItem): support title prop (#7277)
Browse files Browse the repository at this point in the history
* feat(OverflowMenuItem): allow custom titles

* chore: update snapshots

* docs(OverflowMenu): add custom titles to example

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
emyarod and kodiakhq[bot] committed Nov 12, 2020
1 parent c8bb7cd commit d27b3d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,9 @@ Map {
"requireTitle": Object {
"type": "bool",
},
"title": Object {
"type": "string",
},
"wrapperClassName": Object {
"type": "string",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ export const Basic = withReadme(OverflowREADME, () => (
{...props.menuItem()}
itemText="Option 2 is an example of a really long string and how we recommend handling this"
requireTitle
title="Custom tooltip title"
/>
<OverflowMenuItem {...props.menuItem()} itemText="Option 3" />
<OverflowMenuItem {...props.menuItem()} itemText="Option 4" />
<OverflowMenuItem
{...props.menuItem()}
requireTitle
itemText="Danger option"
hasDivider
isDelete
Expand Down
14 changes: 11 additions & 3 deletions packages/react/src/components/OverflowMenuItem/OverflowMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export default class OverflowMenuItem extends React.Component {
* `true` to make this menu item a "danger button".
*/
isDelete: PropTypes.bool,

/**
* The text in the menu item.
*/
itemText: PropTypes.node.isRequired,

/**
* event handlers
*/
Expand All @@ -64,9 +66,7 @@ export default class OverflowMenuItem extends React.Component {
onKeyUp: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseEnter: PropTypes.func,

onMouseLeave: PropTypes.func,

onMouseUp: PropTypes.func,

/**
Expand All @@ -79,10 +79,17 @@ export default class OverflowMenuItem extends React.Component {
'be removed in the next major release of `carbon-components-react`. ' +
'Opt for `selectorPrimaryFocus` in `<OverflowMenu>` instead'
),

/**
* `true` if this menu item has long text and requires a browser tooltip
*/
requireTitle: PropTypes.bool,

/**
* Specify a title for the OverflowMenuItem
*/
title: PropTypes.string,

/**
* The CSS class name to be placed on the wrapper list item element
*/
Expand Down Expand Up @@ -141,6 +148,7 @@ export default class OverflowMenuItem extends React.Component {
wrapperClassName,
requireTitle,
index,
title,
...other
} = this.props;

Expand Down Expand Up @@ -193,7 +201,7 @@ export default class OverflowMenuItem extends React.Component {
onKeyDown(evt);
}}
ref={this.overflowMenuItem}
title={requireTitle ? itemText : null}
title={requireTitle ? title || itemText : null}
tabIndex="-1"
index={index}>
{OverflowMenuItemContent}
Expand Down

0 comments on commit d27b3d3

Please sign in to comment.