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

fix(ui-react): Whitespace in Tab IDs #5378

Merged
merged 6 commits into from
Aug 6, 2024
Merged

fix(ui-react): Whitespace in Tab IDs #5378

merged 6 commits into from
Aug 6, 2024

Conversation

axelEandrews
Copy link
Contributor

@axelEandrews axelEandrews commented Jul 9, 2024

Adds groupId to TabsContext such that unique IDs can be created for each tab group. IDs are of the form ${groupId}-tab-${idValue} for tabs, and${groupId}-panel-${idValue} for panels. idValue is the given value stripped of its whitespace using the added constant WHITESPACE_VALUE. idValue is created in TabsPanel and TabsItem, so assuming the developer enters the same values for these two elements the functionality works. defaultValue and controlled tab functionality still works because the actual value of the tabs is not altered in any way, but it is highly recommended to not assign value to a string containing whitespace.

Outer html output for a tablist with given values: ['Tab 1', 'Tab 2', 'Tab 3']: <div role="tablist" class="amplify-tabs__list" style="justify-content: flex-start;"><button role="tab" id="amplify-id-:rl:-tab-Tab-1" aria-selected="true" aria-controls="amplify-id-:rl:-panel-Tab-1" class="amplify-tabs__item amplify-tabs__item--active">Tab 1</button><button role="tab" id="amplify-id-:rl:-tab-Tab-2" aria-selected="false" aria-controls="amplify-id-:rl:-panel-Tab-2" tabindex="-1" class="amplify-tabs__item">Tab 2</button><button disabled="" role="tab" id="amplify-id-:rl:-tab-Tab-3" aria-selected="false" aria-controls="amplify-id-:rl:-panel-Tab-3" tabindex="-1" class="amplify-tabs__item">Disabled tab</button></div>

Also updated the ComposedTabsExample.tsx file such that each Tab has unique content (previously each was "Tab 1 Content").

Issue #, if available

#5220

#5302 is an old version of this PR that had errors

Description of how you validated changes

Added tests to confirm IDs are the same for tabs in the same tab group with the same given value (should be avoided in practice), IDs are different for tabs in different groups with the same value (fine to do in practice). Also confirms that tabs in same group with different values yield unique IDs. Passes all yarn tests.

Also, edited the Amplify UI Docs examples to explore cases where value and defaultValue are passed with whitespace to ensure composability, control, and disable still work as intended. User experience perfectly matches the production version of Amplify UI Docs.

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • [] Relevant documentation is changed or added (and PR referenced)
  • yarn test passes and tests are updated/added
  • No side effects or sideEffects field updated

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@axelEandrews axelEandrews requested a review from a team as a code owner July 9, 2024 23:02
Copy link

changeset-bot bot commented Jul 9, 2024

🦋 Changeset detected

Latest commit: 7a9bcdd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@aws-amplify/ui-react Patch
@aws-amplify/ui-react-auth Patch
@aws-amplify/ui-react-liveness Patch
@aws-amplify/ui-react-notifications Patch
@aws-amplify/ui-react-storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

hbuchel
hbuchel previously approved these changes Jul 10, 2024
Copy link
Contributor

@hbuchel hbuchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-ran through pa11y, axe and VoiceOver and looks good to me!

timngyn
timngyn previously approved these changes Jul 11, 2024
@axelEandrews axelEandrews dismissed stale reviews from timngyn and hbuchel via f3701a8 July 11, 2024 23:18
timngyn
timngyn previously approved these changes Jul 16, 2024
hbuchel
hbuchel previously approved these changes Jul 18, 2024
@axelEandrews axelEandrews removed the request for review from calebpollman July 18, 2024 16:21
Comment on lines +38 to +40
id={`${groupId}-tab-${idValue}`}
aria-selected={isActive}
aria-controls={`${value}-panel`}
aria-controls={`${groupId}-panel-${idValue}`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If idValue is undefined then the values used on lines 38 and 40 will not be unique

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value for TabsPanel and TabsItem is required to be a string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the testing I've done this change does not seem to be breaking. At this stage of the Tabs composition value is required to be defined, so creating idValue based on it does not seem to introduce any errors. Because value itself is not changed, as long as defaultValue matches the intended target Tab's value the controllability and default functionality seems to work as intended. Tested by changing value and defaultValue for the examples to include whitespace.

Copy link
Member

@timngyn timngyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@axelEandrews axelEandrews merged commit e52db7b into main Aug 6, 2024
35 checks passed
@axelEandrews axelEandrews deleted the fix-tab-ids branch August 6, 2024 17:28
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.

4 participants