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

Using tagName JSX variable for MenuItem #3061

Merged
merged 2 commits into from
Nov 15, 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
11 changes: 9 additions & 2 deletions packages/core/src/components/menu/menuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
* @default true
*/
shouldDismissPopover?: boolean;

/**
* Name of the HTML tag that wraps the MenuItem.
* @default "a"
*/
tagName?: keyof JSX.IntrinsicElements;
}

export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorHTMLAttributes<HTMLAnchorElement>> {
Expand All @@ -95,6 +101,7 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
popoverProps,
shouldDismissPopover,
text,
tagName: TagName = "a",
...htmlProps
} = this.props;
const hasSubmenu = children != null;
Expand All @@ -114,14 +121,14 @@ export class MenuItem extends React.PureComponent<IMenuItemProps & React.AnchorH
);

const target = (
<a {...htmlProps} {...(disabled ? DISABLED_PROPS : {})} className={anchorClasses}>
<TagName {...htmlProps} {...(disabled ? DISABLED_PROPS : {})} className={anchorClasses}>
<Icon icon={icon} />
<Text className={Classes.FILL} ellipsize={!multiline}>
{text}
</Text>
{this.maybeRenderLabel(labelElement)}
{hasSubmenu && <Icon icon="caret-right" />}
</a>
</TagName>
);

const liClasses = classNames({ [Classes.MENU_SUBMENU]: hasSubmenu });
Expand Down