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

Add menu item classnames #3251

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Changes from 2 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
15 changes: 12 additions & 3 deletions packages/core/src/components/menu/menuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
/** Item text, required for usability. */
text: React.ReactNode;

/** Classname for text wrapper element. */
giladgray marked this conversation as resolved.
Show resolved Hide resolved
textClassName?: string;

/** Whether this menu item should appear with an active state. */
active?: boolean;

Expand Down Expand Up @@ -51,6 +54,11 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
*/
labelElement?: React.ReactNode;

/**
* Classname for the right-aligned label wrapper element.
giladgray marked this conversation as resolved.
Show resolved Hide resolved
*/
labelClassName?: string;

/**
* Whether the text should be allowed to wrap to multiple lines.
* If `false`, text will be truncated with an ellipsis when it reaches `max-width`.
Expand Down Expand Up @@ -101,6 +109,7 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
popoverProps,
shouldDismissPopover,
text,
textClassName,
tagName: TagName = "a",
...htmlProps
} = this.props;
Expand All @@ -123,7 +132,7 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
const target = (
<TagName {...htmlProps} {...(disabled ? DISABLED_PROPS : {})} className={anchorClasses}>
<Icon icon={icon} />
<Text className={Classes.FILL} ellipsize={!multiline}>
<Text className={classNames(Classes.FILL, textClassName)} ellipsize={!multiline}>
{text}
</Text>
{this.maybeRenderLabel(labelElement)}
Expand All @@ -136,12 +145,12 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
}

private maybeRenderLabel(labelElement?: React.ReactNode) {
const { label } = this.props;
const { label, labelClassName } = this.props;
if (label == null && labelElement == null) {
return null;
}
return (
<span className={Classes.MENU_ITEM_LABEL}>
<span className={classNames(Classes.MENU_ITEM_LABEL, labelClassName)}>
{label}
{labelElement}
</span>
Expand Down