Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OverflowMenuItem): support title prop #7277

Merged
Show file tree
Hide file tree
Changes from 3 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
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