-
Notifications
You must be signed in to change notification settings - Fork 100
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
INSTUI-4241: fix(ui-toggle-details): do not put aria-expanded and aria-controls on the toggle if there is nothing to toggle #1747
Conversation
… the toggle if there is nothing to toggle Also do not render an empty div for the details in this case. Note that this might break tests since they might find these DOM parts via these ARIA tags. Also the empty div took up a small space when expanded (0.375rem), this might cause layout changes TEST PLAN: Make a ToggleDetails without any children, it should have no aria tags. Should still listen to mouse events
onToggle: function () {}, | ||
children: null |
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.
this is just removing some old old code, ancient InstUI loved default values even when it was not needed.
return { | ||
...props, |
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.
this is better, users cannot override our props this way
// Do not put aria-controls and aria-expanded into the toggle if there | ||
// is nothing to open | ||
const tProps = this.props.children | ||
? toggleProps | ||
: { onClick: toggleProps.onClick } | ||
const props = { | ||
...omitProps(this.props, ToggleDetails.allowedProps), | ||
...toggleProps, | ||
...tProps, | ||
children: this.renderSummary(expanded) | ||
// spread operator makes toggleProps loose Record<string, any>> | ||
} as Record<string, any> | ||
} as Record<string, unknown> |
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.
The actual fix
@@ -152,11 +155,11 @@ class ToggleDetails extends Component<ToggleDetailsProps> { | |||
} | |||
|
|||
renderDetails(expanded: boolean, detailsProps: { id: string }) { | |||
const { children } = this.props | |||
if (!this.props.children) return null | |||
const expandedStyles = expanded ? { display: 'block' } : { display: 'none' } | |||
return ( | |||
<div {...detailsProps} css={[this.props.styles?.details, expandedStyles]}> |
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.
This div
is rendering a line with 0.375rem when open even when it has no children. I've removed this, hopefully nothing will break
|
Also do not render an empty div for the details in this case. Note that this might break tests since
they might find these DOM parts via these ARIA tags. Also the empty div took up a small space when expanded (0.375rem), this might cause layout changes
TEST PLAN:
Make a ToggleDetails without any children, it should have no aria tags. Should still listen to mouse events