-
Notifications
You must be signed in to change notification settings - Fork 227
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
feat(menu-surface): add component #295
Conversation
…terial-components-web-react into feat/menu-surface
@@ -0,0 +1,149 @@ | |||
# React Menu Surface |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Codecov Report
@@ Coverage Diff @@
## master #295 +/- ##
==========================================
+ Coverage 97.14% 97.24% +0.09%
==========================================
Files 35 36 +1
Lines 1367 1489 +122
Branches 131 163 +32
==========================================
+ Hits 1328 1448 +120
- Misses 39 41 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like setting the anchor corner doesn't do the same thing as in MDC Web...try setting it to BOTTOM_END
and see what happens
window.removeEventListener('contextmenu', this.rightClickCallback_); | ||
} | ||
|
||
setAnchorElement = (element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why update state here instead of using createRef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want the component to re-render when the ref is set. I put it on state, so that it renders again once it sets. Otherwise I did a forceRender(), which isn't as obvious.
packages/menu-surface/index.js
Outdated
} | ||
|
||
hoistToBody() { | ||
// this deviatees from the mdc web version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"deviates"
// this deviatees from the mdc web version. | ||
// here we force the menu to hoist, and require either | ||
// this.props.(x,y) or this.props.anchorElement. | ||
if (!(this.menuSurfaceElement_ && this.menuSurfaceElement_.current)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the null check for this.menuSurfaceElement_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its safer to keep it in. adapter.restoreFocus
is called within foundation.close()
. foundation.close
is called in handleBodyClick
and handleKeydown
, which are async events. There is the possibility that the MenuSurface is unmounted before a keydown event or a click event occurs, which would cause an error.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One typo, otherwise LGTM!
removeMenuFromBody(wrapper); | ||
}); | ||
|
||
test('update to props.open sets firstFocusableElement_', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lastFocusableElement_"
Oh one thing I noticed was that the menu surface doesn't trap focus like the MDC Web one. We can either fix that in this PR or open a new bug for it |
@bonniezhou I don't think menu-surface traps focus. Menu does - is that what you meant? |
Oh it might have been menu that I was looking at. Disregard! :) |
fixes #188