Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Menu): Make Submenu open state controlled #1125

Merged
merged 20 commits into from
Apr 1, 2019

Conversation

sophieH29
Copy link
Contributor

This PR aims make submenu open state controlled, thus to bring the flexibility of using submenu and rewrite default behavior.

@codecov
Copy link

codecov bot commented Mar 28, 2019

Codecov Report

Merging #1125 into master will decrease coverage by 0.04%.
The diff coverage is 27.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1125      +/-   ##
==========================================
- Coverage   82.38%   82.33%   -0.05%     
==========================================
  Files         730      730              
  Lines        8685     8684       -1     
  Branches     1167     1232      +65     
==========================================
- Hits         7155     7150       -5     
- Misses       1515     1519       +4     
  Partials       15       15
Impacted Files Coverage Δ
...b/accessibility/Behaviors/Menu/menuItemBehavior.ts 100% <ø> (ø) ⬆️
...kages/react/src/components/Accordion/Accordion.tsx 66% <0%> (ø) ⬆️
packages/react/src/lib/AutoControlledComponent.tsx 94.23% <100%> (-0.6%) ⬇️
packages/react/src/components/Menu/MenuItem.tsx 59.48% <14.28%> (-1.78%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b82f349...ac3c1d9. Read the comment docs.

*/
trySetState = (maybeState, state?) => {
trySetState = (state: Partial<S>, callback?: () => void) => {
const { autoControlledProps } = this.constructor as any
if (process.env.NODE_ENV !== 'production') {
Copy link
Member

Choose a reason for hiding this comment

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

This check should be removed, otherwise we will get incorrect warnings

...this.props,
menuOpen: newValue,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this method, but I don't have a better option now...

key: '3',
content: 'item3',
menu: [{ key: '1', content: 'item3.1' }, { key: '2', content: 'item3.2' }],
},
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to make it more compact:

menu: [
  { key: '1', content: 'item1' },
  { key: '2', content: 'item2' },
  { key: '3', content: 'item3' },
],

Copy link
Member

Choose a reason for hiding this comment

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

As it will become more compact, do we need renderItems() at all?

<span>{`Editorials menu item requested to change its submenu open state to "${
this.state.editorialsMenuOpen
}".`}</span>
<Menu defaultActiveIndex={0} items={this.renderItems()} />
Copy link
Member

Choose a reason for hiding this comment

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

This looks unreadable 🤔

What about something like this:

<Header as="h5" content="Current state:" />
<pre>{JSON.stringify(this.state, null, 2)}</pre>
<Divider />
<Menu defaultActiveIndex={0} items={this.renderItems()} />
  

/>
}
/>
)
Copy link
Member

Choose a reason for hiding this comment

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

Should we revert these changes?

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, yeah. Did some testing, great you noticed

_.invoke(this.props, 'onActiveChanged', e, { ...this.props, active: true })
e.stopPropagation()
e.preventDefault()
}
}

private trySetMenuOpen(newValue: boolean, eventArgs: any, onStateChanged?: any) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private trySetMenuOpen(newValue: boolean, eventArgs: any, onStateChanged?: any) {
private trySetMenuOpen(e: React.SyntethicEvent, newValue: boolean, onStateChanged?: any) {

nit: Can we place e param on the first place as in other methods?

Copy link
Contributor Author

@sophieH29 sophieH29 Apr 1, 2019

Choose a reason for hiding this comment

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

fyi, the order is the same as in Popup for trySetOpen method.
And the other thing, if you would want to change state without event, you would have to call
trySetMenuOpen(null, newValue)
instead of trySetMenuOpen(newValue). I would leave an order as it is as I think the newValue param has biggest priority than event object

if (state) newState = { ...newState, ...state }

if (Object.keys(newState).length > 0) this.setState(newState)
if (Object.keys(newState).length > 0) this.setState(newState, callback)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure, that we really need this condition, but let's leave it as is for now

@sophieH29 sophieH29 merged commit fbfc3c7 into master Apr 1, 2019
@sophieH29 sophieH29 deleted the feat/submenu-autocontrolled branch April 1, 2019 10:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants