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 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
17 changes: 14 additions & 3 deletions packages/core/src/components/menu/menuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
*/
label?: string;

/**
* A space-delimited list of class names to pass along to the right-aligned label wrapper element.
*/
labelClassName?: string;

/**
* Right-aligned label content, useful for displaying hotkeys.
*/
Expand Down Expand Up @@ -76,6 +81,11 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
* @default "a"
*/
tagName?: keyof JSX.IntrinsicElements;

/**
* A space-delimited list of class names to pass along to the text wrapper element.
*/
textClassName?: string;
}

export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorHTMLAttributes<HTMLAnchorElement>> {
Expand All @@ -101,6 +111,7 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
popoverProps,
shouldDismissPopover,
text,
textClassName,
tagName: TagName = "a",
...htmlProps
} = this.props;
Expand All @@ -123,7 +134,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 +147,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