Skip to content
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

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

matyasf
Copy link
Collaborator

@matyasf matyasf commented Oct 24, 2024

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

… 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
@matyasf matyasf self-assigned this Oct 24, 2024
Comment on lines -47 to -48
onToggle: function () {},
children: null
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

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

Comment on lines +104 to +113
// 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>
Copy link
Collaborator Author

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]}>
Copy link
Collaborator Author

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

Copy link

github-actions bot commented Oct 24, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-10-28 11:11 UTC

@matyasf matyasf merged commit 82094c3 into master Oct 28, 2024
11 checks passed
@matyasf matyasf deleted the fix_toggleDetails_a11y branch October 28, 2024 11:11
@HerrTopi HerrTopi removed their request for review October 28, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants