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(material/sort): add description input for sort-header #23633

Merged
merged 1 commit into from
Oct 13, 2021

Conversation

jelbourn
Copy link
Member

Adds a description input for mat-sort-header so that developers can provide an accessible description (using AriaDescirber under the hood). Additionally update the accessibility section for the sort header's documentation with guidance on providing an accessible experience.

I decided to use this approach instead of expanding MatSortHeaderIntl because the message developers would want to set here depends on several bits of information, including:

  • Whether the column is currently sorted
  • The sort direction
  • Whether users can clear sorting (configured on MatSort)
  • The name of the column (not the ID)

Accounting for all of these factors would have made the intl formatting too complicated.

This does have the negative consequence of needing to set a description for every header. However, users can add a custom directive to set the description in a consistent way if they have an application with many tables.

cc @zarend @amysorto

@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround Accessibility This issue is related to accessibility (a11y) area: material/sort labels Sep 24, 2021
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 24, 2021
@jelbourn jelbourn added the target: major This PR is targeted for the next major release label Sep 24, 2021
@jelbourn jelbourn requested a review from a team as a code owner September 24, 2021 00:55
@@ -176,6 +199,9 @@ export class MatSortHeader extends _MatSortHeaderBase
{toState: this._isSorted() ? 'active' : this._arrowDirection});

this._sort.register(this);

this._sortButton = this._elementRef.nativeElement.querySelector('[role="button"]')!;
Copy link
Member

Choose a reason for hiding this comment

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

Should we use a ViewChild query to get the button instead of querying directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO I don't see the point of using @ViewChild to query for native DOM elements (vs. directives or injectables)


// If _sortButton is undefined, the component hasn't been initialized yet so there's
// nothing to update in the DOM.
if (this._sortButton) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we also need to check that the description is defined/isn't an empty string here?

Copy link
Member Author

Choose a reason for hiding this comment

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

AriaDescriber already checks the presence of the message internally

@jelbourn jelbourn force-pushed the sort-a11y branch 2 times, most recently from f2e49a2 to 3bb13ed Compare September 24, 2021 14:42
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM, but the CI is failing.

@josephperrott josephperrott removed the request for review from a team September 24, 2021 15:37
@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Sep 24, 2021
Copy link
Contributor

@zarend zarend left a comment

Choose a reason for hiding this comment

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

seems reasonable to me 👍

Adds a description input for mat-sort-header so that developers can provide an accessible description (using AriaDescirber under the hood). Additionally update the accessibility section for the sort header's documentation with guidance on providing an accessible experience.

I decided to use this approach instead of expanding `MatSortHeaderIntl` because the message developers would want to set here depends on several bits of information, including:
* Whether the column is currently sorted
* The sort direction
* Whether users can clear sorting (configured on `MatSort`)
* The name of the column (not the ID)

Accounting for all of these factors would have made the intl formatting too complicated.

This does have the negative consequence of needing to set a description for every header. However, users can add a custom directive to set the description in a consistent way if they have an application with many tables.
@zarend zarend merged commit ecd54f4 into angular:master Oct 13, 2021
zarend pushed a commit that referenced this pull request Oct 13, 2021
Adds a description input for mat-sort-header so that developers can provide an accessible description (using AriaDescirber under the hood). Additionally update the accessibility section for the sort header's documentation with guidance on providing an accessible experience.

I decided to use this approach instead of expanding `MatSortHeaderIntl` because the message developers would want to set here depends on several bits of information, including:
* Whether the column is currently sorted
* The sort direction
* Whether users can clear sorting (configured on `MatSort`)
* The name of the column (not the ID)

Accounting for all of these factors would have made the intl formatting too complicated.

This does have the negative consequence of needing to set a description for every header. However, users can add a custom directive to set the description in a consistent way if they have an application with many tables.

(cherry picked from commit ecd54f4)
zarend pushed a commit that referenced this pull request Oct 13, 2021
Adds a description input for mat-sort-header so that developers can provide an accessible description (using AriaDescirber under the hood). Additionally update the accessibility section for the sort header's documentation with guidance on providing an accessible experience.

I decided to use this approach instead of expanding `MatSortHeaderIntl` because the message developers would want to set here depends on several bits of information, including:
* Whether the column is currently sorted
* The sort direction
* Whether users can clear sorting (configured on `MatSort`)
* The name of the column (not the ID)

Accounting for all of these factors would have made the intl formatting too complicated.

This does have the negative consequence of needing to set a description for every header. However, users can add a custom directive to set the description in a consistent way if they have an application with many tables.

(cherry picked from commit ecd54f4)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accessibility This issue is related to accessibility (a11y) action: merge The PR is ready for merge by the caretaker area: material/sort cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants