-
Notifications
You must be signed in to change notification settings - Fork 155
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: Refactor and fix AppLayout and side navigation panel state and behaviour #1434
Changes from 10 commits
4527c21
3659082
7c83e1c
4c04bab
9cdf71c
24f45cb
ee95ba8
4403d38
5ebd377
b9eb880
2067586
04a961b
ce65c09
6fe253b
df7681e
7f8cc80
4c020a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ interface ExpandableDefaultHeaderProps { | |||||||||||||||||||||||
|
||||||||||||||||||||||||
interface ExpandableNavigationHeaderProps extends Omit<ExpandableDefaultHeaderProps, 'onKeyUp' | 'onKeyDown'> { | ||||||||||||||||||||||||
ariaLabelledBy?: string; | ||||||||||||||||||||||||
disableExpandChangeOnHeaderTextClick?: boolean; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
interface ExpandableHeaderTextWrapperProps extends ExpandableDefaultHeaderProps { | ||||||||||||||||||||||||
|
@@ -49,6 +50,7 @@ interface ExpandableSectionHeaderProps extends Omit<ExpandableDefaultHeaderProps | |||||||||||||||||||||||
headerActions?: ReactNode; | ||||||||||||||||||||||||
headingTagOverride?: ExpandableSectionProps.HeadingTag; | ||||||||||||||||||||||||
ariaLabelledBy?: string; | ||||||||||||||||||||||||
disableExpandChangeOnHeaderTextClick?: boolean; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const ExpandableDeprecatedHeader = ({ | ||||||||||||||||||||||||
|
@@ -93,20 +95,24 @@ const ExpandableNavigationHeader = ({ | |||||||||||||||||||||||
expanded, | ||||||||||||||||||||||||
children, | ||||||||||||||||||||||||
icon, | ||||||||||||||||||||||||
disableExpandChangeOnHeaderTextClick, | ||||||||||||||||||||||||
}: ExpandableNavigationHeaderProps) => { | ||||||||||||||||||||||||
// By using `disableExpandChangeOnHeaderTextClick`, clicking the header text will not toggle the expandable section. | ||||||||||||||||||||||||
// We use this for the "expandable-link-group" in the side navigation. | ||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||
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.
components/src/expandable-section/expandable-section-header.tsx Lines 255 to 265 in 4c020a8
|
||||||||||||||||||||||||
<div id={id} className={clsx(className, styles['click-target'])} onClick={onClick}> | ||||||||||||||||||||||||
<div id={id} className={clsx(className, styles['click-target'])}> | ||||||||||||||||||||||||
<button | ||||||||||||||||||||||||
className={clsx(styles['icon-container'], styles['expand-button'])} | ||||||||||||||||||||||||
aria-labelledby={ariaLabelledBy} | ||||||||||||||||||||||||
aria-label={ariaLabel} | ||||||||||||||||||||||||
aria-controls={ariaControls} | ||||||||||||||||||||||||
aria-expanded={expanded} | ||||||||||||||||||||||||
type="button" | ||||||||||||||||||||||||
onClick={onClick} | ||||||||||||||||||||||||
> | ||||||||||||||||||||||||
{icon} | ||||||||||||||||||||||||
</button> | ||||||||||||||||||||||||
{children} | ||||||||||||||||||||||||
<span onClick={disableExpandChangeOnHeaderTextClick ? () => {} : onClick}>{children}</span> | ||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
}; | ||||||||||||||||||||||||
|
@@ -221,6 +227,7 @@ export const ExpandableSectionHeader = ({ | |||||||||||||||||||||||
onKeyUp, | ||||||||||||||||||||||||
onKeyDown, | ||||||||||||||||||||||||
onClick, | ||||||||||||||||||||||||
disableExpandChangeOnHeaderTextClick, | ||||||||||||||||||||||||
}: ExpandableSectionHeaderProps) => { | ||||||||||||||||||||||||
const icon = ( | ||||||||||||||||||||||||
<InternalIcon | ||||||||||||||||||||||||
|
@@ -256,6 +263,7 @@ export const ExpandableSectionHeader = ({ | |||||||||||||||||||||||
<ExpandableNavigationHeader | ||||||||||||||||||||||||
className={clsx(className, wrapperClassName)} | ||||||||||||||||||||||||
ariaLabelledBy={ariaLabelledBy} | ||||||||||||||||||||||||
disableExpandChangeOnHeaderTextClick={disableExpandChangeOnHeaderTextClick} | ||||||||||||||||||||||||
{...defaultHeaderProps} | ||||||||||||||||||||||||
> | ||||||||||||||||||||||||
{headerText ?? header} | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,9 +227,6 @@ function Link({ definition, expanded, activeHref, fireFollow }: LinkProps) { | |
|
||
const onClick = useCallback( | ||
(event: React.MouseEvent) => { | ||
// Prevent the click event from toggling outer expandable sections. | ||
event.stopPropagation(); | ||
|
||
if (isPlainLeftClick(event)) { | ||
fireFollow(definition, event); | ||
} | ||
|
@@ -403,6 +400,9 @@ function ExpandableLinkGroup({ definition, fireFollow, fireChange, activeHref, v | |
} | ||
}; | ||
|
||
// By using `disableExpandChangeOnHeaderTextClick`, clicking the header text will not toggle the expandable section. | ||
const disableExpandChangeOnHeaderTextClick = true; | ||
|
||
return ( | ||
<InternalExpandableSection | ||
className={clsx( | ||
|
@@ -412,6 +412,7 @@ function ExpandableLinkGroup({ definition, fireFollow, fireChange, activeHref, v | |
variant="navigation" | ||
expanded={userExpanded ?? expanded} | ||
onChange={onExpandedChange} | ||
__disableExpandChangeOnHeaderTextClick={disableExpandChangeOnHeaderTextClick} | ||
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. Can we do this without an internal prop? For example, what if we baked this behavior into the 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. I've changed from using an internal prop (for detecting the desired behaviour of the trigger to expand the section) into the
This is a more impactful change, but between a successful dry-run (ID: 6564992503) and our current guidelines (above), I'm confident this is the best approach. 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. Let's do it! |
||
headerText={ | ||
<Link | ||
definition={{ type: 'link', href: definition.href, text: definition.text }} | ||
|
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.
As opposed to adding more
eslint-disable-next-line
exceptions, I suggest convertingconst onNavigationToggle = useCallback(() => {}, [])
toconst onNavigationToggle = useStableCallback(() => {})
. This value will be safe to put into effects