Skip to content

SplitButton: When in a menu allow the primary portion to collapse submenu#4517

Merged
jspurlin merged 4 commits intomicrosoft:masterfrom
jspurlin:jspurlin/AllowSubMenusToCollapseOnPrimarySplitButton
Apr 11, 2018
Merged

SplitButton: When in a menu allow the primary portion to collapse submenu#4517
jspurlin merged 4 commits intomicrosoft:masterfrom
jspurlin:jspurlin/AllowSubMenusToCollapseOnPrimarySplitButton

Conversation

@jspurlin
Copy link
Copy Markdown
Contributor

SplitButton: Allow the primary portion of a splitButton (when it a menu) to collapse a submenu

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description of changes

Before this PR, the primary portion of a splitButton when in a menu would not collapse another item's submenu (you could only hover over the split portion of the splitButton). This did not align with the behavior of other menu items and felt weird/broken

Focus areas to test

Verified that now the primary portion of splitButtons can collapse submenus (if it is not its own item's submenu) on hover just like all other menu items AND no other behavior changed

iconProps: item.iconProps,
onMouseEnter: this._onItemMouseEnter.bind(this, item, true /* isSplitButtonPrimary */),
onMouseLeave: this._onMouseItemLeave.bind(this, item),
onMouseMove: this._onItemMouseMove.bind(this, item, true /* isSplitButtonPrimary */),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.bind [](start = 40, length = 5)

Question a bit unrelated to the CR, do we not prefer to tag the methods with @autoBind instead of using .bind, this way we dont have to remember to do it? I ask because I think I have seen both ways in the project and wondering if there is a preference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, the usage of autobind has been removed from fabric because of the bloat that came with it. Ideally you want to use functions as variables instead, but in this case since we are passing extra data to the callback we need to use bind

Copy link
Copy Markdown
Contributor

@ddlbrena ddlbrena left a comment

Choose a reason for hiding this comment

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

:shipit:

checked: item.checked,
icon: item.icon,
iconProps: item.iconProps,
onMouseEnter: this._onItemMouseEnter.bind(this, item, true /* isSplitButtonPrimary */),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like we should be treating the two buttons as more separate than they are. SplitButtonPrimary doesn't have submenu items, and shouldn't be treated as such. Instead of adding this, instead do {...item, subMenuProps: null, items: null} in render split button. It keeps it cleaner. You could also parse this further since the icon part of the split button really shouldn't get passed the onclick either.

…s not on the expandable portion of the control.
// Delay updating expanding/dismissing the submenu
// and only set focus if we have not already done so
// and only set focus if we have not already done so.
// Also if we are on the primary portion of a splitButton
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove mention of splitbutton

// (and we know from above that we are not the expanded item)
// collapse the submenu
if (hasSubmenu(item)) {
ev.stopPropagation();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this need to be here now?

Copy link
Copy Markdown
Contributor Author

@jspurlin jspurlin Apr 11, 2018

Choose a reason for hiding this comment

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

I bumped the hover handling on to the whole container of the splitButton since that's what should be getting focus. This was added to make sure when we are hovering over the expandable portion of the splitButton that the event will not bubble up to the parent container. All other cases it doesn't change anything. This PR now also fixes focus not updating correctly when hovering over a splitButton (in a menu), now splitButtons update focus just like the other items

@jspurlin jspurlin merged commit 561707a into microsoft:master Apr 11, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants