Skip to content

Commit

Permalink
Add menu item classnames (#3251)
Browse files Browse the repository at this point in the history
* Add menu item label classname

* Add text classname prop

* Alphabetize props & improve docs
  • Loading branch information
spefley authored and giladgray committed Dec 20, 2018
1 parent 8e1e03d commit ff71092
Showing 1 changed file with 14 additions and 3 deletions.
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

1 comment on commit ff71092

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add menu item classnames (#3251)

Previews: documentation | landing | table

Please sign in to comment.