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

MenuItem supports HTML props, remove submenu prop #2087

Merged
merged 7 commits into from
Feb 7, 2018

Conversation

giladgray
Copy link
Contributor

@giladgray giladgray commented Feb 5, 2018

Fixes #605

Changes proposed in this pull request:

  • MenuItem supports all HTML props
    • ⚠️ add labelElement because label doesn't support JSX (just like Switch etc)
  • 🔥 remove submenu prop: only one way to submenu
  • improve MenuItem props docs
  • pull MenuItem tests to separate file

Gilad Gray added 2 commits February 5, 2018 14:47
@blueprint-bot
Copy link

fix CopyCellsMenuItem usage

Preview: documentation | landing | table

@@ -22,10 +22,32 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
/** Item text, required for usability. */
text: string;

/**
* Children of this component will be rendered in a __submenu__ that appears when hovering or
* clicking on this menu item. You can instead pass an array of props objects to the `submenu` prop
Copy link
Contributor

Choose a reason for hiding this comment

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

incomplete sentence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops


/**
* Whether this menu item is non-interactive. Enabling this prop will ignore `href`, `tabIndex`,
* and mouse event handlers (in particular click, down, enter, leave)
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a trailing period

@@ -148,3 +193,13 @@ const SUBMENU_POPOVER_MODIFIERS: Popper.Modifiers = {
offset: { offset: -5 },
preventOverflow: { boundariesElement: "viewport", padding: 20 },
};

// props to ignore when disabled
const DISABLED_PROPS: React.AnchorHTMLAttributes<HTMLAnchorElement> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: place block-scoped variables above their usage sites

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what does this mean? where can i move this constant? it's defined outside the class so it'll actually be static, and used once in render().

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant above the class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what i thought we were in the habit of putting statics at the bottom?

Copy link
Contributor

Choose a reason for hiding this comment

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

feels weird for const, more acceptable for function since those get hoisted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hoisted? both feel precisely the same level of weird to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const gets hoisted too: functions and variables.

and it's used inside a function (not synchronously), so guaranteed to be defined.

@blueprint-bot
Copy link

trailing periods.

Preview: documentation | landing | table

@@ -22,10 +22,32 @@ export interface IMenuItemProps extends IActionProps, ILinkProps {
/** Item text, required for usability. */
text: string;

/**
* Children of this component will be rendered in a __submenu__ that appears when hovering or
* clicking on this menu item. You can instead pass an array of props objects to the `submenu` prop.
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't understand this second sentence. Instead of what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

submenu array instead of children elements. how can i clarify?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to say that a user can render a submenu with either children or the submenu prop? (the "instead" wording works counter to this, it suggests that only one option works)

Why do we want to support that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that's what I mean to say. this has been supported forever.

remember when I asked about making MenuItem children into the content (text) of the item and relegating submenu to props only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 proposal: submenu?: React.ReactNode; submenuProps?: IMenuItemProps[]

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather not break the API here and only support one usage pattern for submenus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one usage pattern

but we already support two patterns, and have for a very long time

not break the API

removing one usage pattern would be an API break...

what should I do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a cursory search suggests no one is using the submenu prop, but hard to verify.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh ok I thought this was adding new support. in that case I'd suggest removing the submenu prop while we can in 2.0

@giladgray giladgray changed the title MenuItem supports HTML props MenuItem supports HTML props, remove submenu prop Feb 6, 2018
{ icon: "align-center", text: "Align Center" },
{ icon: "align-right", text: "Align Right" },
];
const wrapper = shallow(<MenuItem icon="align-left" text="Alignment" submenu={items} />);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted this test

);
const submenu = findSubmenu(wrapper);
assert.lengthOf(submenu.props.children, 2);
assert.isTrue(warnSpy.alwaysCalledWith(MENU_WARN_CHILDREN_SUBMENU_MUTEX));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted this test

@blueprint-bot
Copy link

only one way to submenu: remove submenu prop

Preview: documentation | landing | table

@blueprint-bot
Copy link

fix iconName usage in tests (semantic merge)

Preview: documentation | landing | table

@adidahiya adidahiya merged commit eeeff7d into develop Feb 7, 2018
@adidahiya adidahiya deleted the gg/menuitem-props branch February 7, 2018 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants