-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(sidenav): sidenavmenu stays open when in rail #3626
Merged
jnm2377
merged 13 commits into
carbon-design-system:master
from
matthew-chirgwin:3527-submenu-not-collapsing-in-rails
Aug 22, 2019
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b0866e0
fix(sidenav): sidenavmenu stays open when in rail
b64d688
Merge branch 'master' into 3527-submenu-not-collapsing-in-rails
tw15egan 7d8788f
fix(sidenav): sidenavmenu stays open when in rail
d67f853
Merge branch 'master' into 3527-submenu-not-collapsing-in-rails
tw15egan 0a3293a
fix(sidenav): sidenavmenu stays open when in rail
62c79d9
fix(sidenav): sidenavmenu stays open when in rail
1688fee
fix(sidenav): sidenavmenu stays open when in rail
0d177f7
fix(sidenav): make sidenav open/close via keyboard
0a034e8
fix(sidenav): make sidenav open/close via keyboard
ee67d78
fix(sidenav): sidenavmenu stays open when in rail
136970f
Merge branch 'master' into 3527-submenu-not-collapsing-in-rails
matthew-chirgwin 340a641
Merge branch 'master' into 3527-submenu-not-collapsing-in-rails
tw15egan 94d6a0d
Merge branch 'master' into 3527-submenu-not-collapsing-in-rails
matthew-chirgwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,9 @@ const SideNav = React.forwardRef(function SideNav(props, ref) { | |||||
|
||||||
const { current: controlled } = useRef(expandedProp !== undefined); | ||||||
const [expandedState, setExpandedState] = useState(defaultExpanded); | ||||||
const [expandedViaHoverState, setExpandedViaHoverState] = useState( | ||||||
defaultExpanded | ||||||
); | ||||||
const expanded = controlled ? expandedProp : expandedState; | ||||||
const handleToggle = (event, value = !expanded) => { | ||||||
if (!controlled) { | ||||||
|
@@ -42,6 +45,9 @@ const SideNav = React.forwardRef(function SideNav(props, ref) { | |||||
if (onToggle) { | ||||||
onToggle(event, value); | ||||||
} | ||||||
if (controlled || isRail) { | ||||||
setExpandedViaHoverState(value); | ||||||
} | ||||||
}; | ||||||
|
||||||
const accessibilityLabel = { | ||||||
|
@@ -56,7 +62,7 @@ const SideNav = React.forwardRef(function SideNav(props, ref) { | |||||
|
||||||
const className = cx({ | ||||||
[`${prefix}--side-nav`]: true, | ||||||
[`${prefix}--side-nav--expanded`]: expanded, | ||||||
[`${prefix}--side-nav--expanded`]: expanded || expandedViaHoverState, | ||||||
[`${prefix}--side-nav--collapsed`]: !expanded && isFixedNav, | ||||||
[`${prefix}--side-nav--rail`]: isRail, | ||||||
[customClassName]: !!customClassName, | ||||||
|
@@ -69,6 +75,21 @@ const SideNav = React.forwardRef(function SideNav(props, ref) { | |||||
[`${prefix}--side-nav__overlay-active`]: expanded, | ||||||
}); | ||||||
|
||||||
let childrenToRender = children; | ||||||
|
||||||
// if a rail, pass the expansion state as a prop, so children can update themselves to match | ||||||
if (isRail) { | ||||||
childrenToRender = React.Children.map(children, child => { | ||||||
// if we are controlled, check for if we have hovered over or the expanded state, else just use the expanded state (uncontrolled) | ||||||
let currentExpansionState = controlled | ||||||
? expandedViaHoverState || expanded | ||||||
: expanded; | ||||||
return React.cloneElement(child, { | ||||||
isSideNavExpanded: currentExpansionState, | ||||||
}); | ||||||
}); | ||||||
} | ||||||
|
||||||
return ( | ||||||
<> | ||||||
{isFixedNav ? null : <div className={overlayClassName} />} | ||||||
|
@@ -78,9 +99,9 @@ const SideNav = React.forwardRef(function SideNav(props, ref) { | |||||
{...accessibilityLabel} | ||||||
onFocus={event => handleToggle(event, true)} | ||||||
onBlur={event => handleToggle(event, false)} | ||||||
onMouseEnter={() => handleToggle(true)} | ||||||
onMouseLeave={() => handleToggle(false)}> | ||||||
{children} | ||||||
onMouseEnter={() => handleToggle(true, true)} | ||||||
onMouseLeave={() => handleToggle(false, false)}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asudoh - same here as my comment above |
||||||
{childrenToRender} | ||||||
</nav> | ||||||
</> | ||||||
); | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
@asudoh - before my changes,
handleToggle
was called here with just true as the only argument. I can change it to whatever the event is as you suggest, but if someone downstream passes theonToggle
property to theSideNav
and expects the bool value, would that not be a breaking change for them?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.
Thank you for putting your thoughts on this and elaborating it @matthew-chirgwin! I now see your point (I missed it, tricked by argument name), and I now think the best is keeping
handleToggle()
call intact - Meaning, call with one arg.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.
Hi @asudoh - the only issue with moving to one argument is the effect that would then have on how I changed
handleToggle
to handle this case (lines 48-50). That change could be pushed into its own function, but would that add any value?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.
Just leaving a note, though this is merged already; I think the best approach is making
handleToggle()
obvious that the first arg is optional and and the second arg becomes the first arg when the caller doesn't specify the first arg.