Skip to content

Conversation

kevin-brown
Copy link
Member

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • Properly set title attribute for rendered selection in single select when placeholder is visible

If this is related to an existing ticket, include a link to it as well.

Fixes #5963

This sets the title of the rendered selection for a placeholder when
it is displayed within a single select. This is not necessary for a
multiple select because the placeholder is set on the search box
which will properly convey the value of it and meets ARIA guidelines.

Because single select boxes currently use a `textbox` role to convey
the keyboard accessibility of the textbox area, and because that role
is currently required in ARIA 1.1, it must be properly labelled using
the `title`, `aria-label`, or `aria-labelledby` attribute. This
currently happens for single selects without a placeholder, and
single selects with a placeholder but with an active selection,
because the `title` attribute is set to the title of the active
selection. Because it only currently sets it for the active selection,
this caused an edge case specific to placeholders for single selects
where the selection was not properly labelled.

The placeholder title follows the same rules for setting the attribute
value as for the regular single select selection, except placeholders
will also fall back to just using the text value of the placeholder
element in the event that the `title` and `text` attributes are not
specified on the placeholder data option.
@kevin-brown kevin-brown added this to the 4.1.0 milestone Jan 23, 2021
@kevin-brown kevin-brown merged commit 2cf64df into develop Jan 23, 2021
@kevin-brown kevin-brown deleted the GH-5963 branch January 23, 2021 04:02
anttikuuskoski pushed a commit to anttikuuskoski/select2 that referenced this pull request Mar 29, 2022
This sets the title of the rendered selection for a placeholder when
it is displayed within a single select. This is not necessary for a
multiple select because the placeholder is set on the search box
which will properly convey the value of it and meets ARIA guidelines.

Because single select boxes currently use a `textbox` role to convey
the keyboard accessibility of the textbox area, and because that role
is currently required in ARIA 1.1, it must be properly labelled using
the `title`, `aria-label`, or `aria-labelledby` attribute. This
currently happens for single selects without a placeholder, and
single selects with a placeholder but with an active selection,
because the `title` attribute is set to the title of the active
selection. Because it only currently sets it for the active selection,
this caused an edge case specific to placeholders for single selects
where the selection was not properly labelled.

The placeholder title follows the same rules for setting the attribute
value as for the regular single select selection, except placeholders
will also fall back to just using the text value of the placeholder
element in the event that the `title` and `text` attributes are not
specified on the placeholder data option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Placeholder should have a title for WCAG AA compliance
1 participant