1
0
mirror of synced 2024-11-22 21:16:10 +03:00
Commit Graph

30 Commits

Author SHA1 Message Date
Kevin Brown
e5131d0cc8
Set the main ARIA 1.1 roles and properties for comboboxes (#5582)
* Move search accessibility tests under selection tests

* Set aria-activedescendent and aria-owns on selection search

This is a reduced version of a5ab08b49cb which is split out to only
set the `aria-activedescendent` and `aria-owns` attributes on the
search box located within the selection container. This is the search
box used within a multiple select, and previously it did not always
set these two attributes correctly.

One major change here is that we clear the `aria-activedescendent`
attribute if the result that is selected does not have an ID. This
was not being done previously, instead the attribute was still
containing the old value, and it meant that sometimes the wrong
result was being pointed to.

The test coverage for this was also expanded to ensure that these
attributes are properly being set.

* Set aria-activedescendent and aria-owns on dropdown search

This is a reduced version of a5ab08b49cb which is split out to only
set the `aria-activedescendent` and `aria-owns` attributes on the
search box located within the dropdown. This is the search box used
within a single select, and previously it did not set these two
attributes at all. Additionally, it did not set the `aria-autocomplete`
attribute, which is also needed for screen readers to properly read
through the list of results.

There was previously no test coverage for this, so the tests were
largely copied from the tests for selection search.

* Set proper ARIA roles on result elements

When Select2 4.0.0 was originally written, accessibility was tested
using the Orca screen reader and Mozilla Firefox as the browser.
Because a `<select>` box could contain `<optgroup>` elements, which
can further contain additional `<option>` elements, Orca would read
out a `<select>` box as a tree view. Apparently Orca was the only
screen reader to do this, but Select2 maintained this behaviour
because the ARIA spec did not allow grouping elements for the right
roles.

In the ARIA 1.2 spec, an element with the role of `listbox` (which
is the proper one for representing a `<select>` element) can now
contain elements with the role of `group` that can be used for
grouping. This means that now Select2 can switch to use the proper
ARIA roles to better match how most browsers represent the `<select>`
element out of the box.

As a result, instead of the Select2 results list being represented
as a tree containing tree items, it is now represented as a listbox
containing options and groups. Notices will be represented as an
alert, which more closely represents what they were being used for.

This is a reduced version of a5ab08b49cb which is split out to only
fix the `role` attributes on elements within the results list.

* Switch search boxes to have a role of searchbox

I'm pretty sure this is implicit now, but since we used to specify
that the search box had a role of `textbox`, we may as well migrate
that over to specify the role of `searchbox`. This is different
from the original pull request where this role was changes to
`combobox`, but that is because we are working against the ARIA 1.2
spec and the original pull request was working agianst the ARIA 1.0
spec, which required the search box to have that role.

* Set aria-controls instead of aria-owns on search boxes

In ARIA 1.1, there was a switch to use `aria-controls` on the search
box to point to the results list instead of using `aria-owns`. This
is required because the `combobox`, in our case the selection
container, should have the `aria-owns` attribute pointing to the
results list. And because only one elment can own another element,
we must fall back to `aria-controls` to represent that relationship.

The tests have also been adjusted to reflect this new discovery.
2019-07-29 22:34:24 -04:00
Kevin Brown
f14bdf6b7b
Fix search box expanding width of container (#5595)
This fixes a bug with the search box where, when it had a placeholder,
it would expand the width of the selection container because it was
too large. This bug was specifically caused by the search box not
factoring in the padding surrounding it when caclualting the width
it needed to be, which resulted in the search box extending
outside of the selection container. This bug was easy to notice if
your Select2 was set to have 100% width and if the container it was
held within was not a block element.

This fixes the bug by switching to using `width()` for calculating
the search width instead of using `innerWidth()`, which ignored the
surrounding padding.

Fixes #5517
Closes #5518
2019-07-29 22:25:19 -04:00
Kevin Brown
efbfd14414
Remove selection title attribute if text is empty (#5589)
This fixes a bug that was introduced in Select2 4.0.0 and only
partially fixed in Select2 4.0.6-rc.0 where the `title` attribute
that is set on the selection container (or individual selections,
for a multiple select) is not cleared when the text/title of the
option is not set. In most cases, users no longer see this issue
because the `text` property of most data objects is set, so the
`title` attribute will always be cleared correctly. There was a bug
for cases where the `text` property was not set, or where the `text`
property was set to an empty string, that resulted in the `title`
attribute persisting with the incorrect value.

We have fixed this issue by always removing the `title` attribute
from the selection (or not adding it in the first place, for a
multiple select) when the `text` and `title` properties of the data
object are empty or not present.

This also adds in a series of tests to ensure the `title` attribute
is set properly in a variety of cases, building upon the ones that
already existed.

Fixes #3895
2019-07-28 00:36:51 -04:00
Kevin Brown
f2d527ea97
Do not propagate click when search box is not empty (#5580)
This fixes a long-standing bug where if you tried to click in the
search box for a multiple select while there was text in it, the
dropdown would close and the text would be cleared. This caused
many unexpected issues, because it meant that you could only use
your keyboard to edit text within the search box.

This will still clear out the search field if you click within the
area of the selection which is not the search field. I'm not sure
if that is also unexpected behaviour, so for now I am going to
maintain it.

Fixes #3517
Fixes #3808
Fixes #5491
Closes #5551
2019-07-21 13:04:51 -04:00
Kevin Brown
bbd320d75e Convert source and tests to unix newlines 2019-07-20 23:01:38 -04:00
Kevin Brown
1b5a962819
Revert change to focusing behaviour in 4.0.6 (#5576)
This behaviour, where the focus was happening on a small asynchronous
delay, was added in commit 933189b92 late last year in a commit with
no supporting tickets or commit message explaining what the change
was trying to accomplish. This commit has effectly been reverted within
this commit, since it caused a regression in how focus was being
assigned that made it inconsistent with a standard `<select>`.

A test was added for this which ensures that we won't see that
regression again.

Fixes #5532
Fixes #5185
Closes #5552
2019-07-20 22:44:28 -04:00
Nisha Kaushik
14a059d7ee #4530 Add tooltip (title) to the 'remove all' 'X' icon. (#5291)
* #4530 Add tooltip (title) to the 'remove all' 'X' icon.

* #4530 Add tooltip (title) to the 'remove all' 'X' icon.

* #4530 Add tooltip (title) to the 'remove all'

* Revert dist folder.

* add tk.js from pull request.
2018-09-15 16:22:54 -03:00
Tim Kang
a395ad1d75 Add failing tests
See #3895
2017-10-26 12:59:04 -04:00
Krzysztof Śmiałek
04d3a5da66 Add dedicated event for clearing
Closes #4929, #5045.
2017-10-26 00:30:31 -04:00
Krzysztof Śmiałek
10bda78b37 Fix value not being cleared when unselect event is emitted
Fixes #5049.
2017-10-26 00:30:24 -04:00
Kevin Brown
a74547aaa7 Migrate from expect to assert.expect
After we upgraded to QUnit 1.23.1, we gained support for
assert.expect(). This allows us to guard against any race conditions
within tests, because now expect() will be linked to the specific test
instead of the current running test.
2016-05-23 23:38:45 -04:00
Kevin Brown
5b207b287e Add test for focus event on inline search
This adds a test for
02cca7baa7.
2016-04-23 21:38:41 -04:00
Kevin Brown
e08222ef15 Tests for the inline search box
This adds tests for the following commits

5f80c5d9f8

395e06aff5
2015-11-23 18:25:09 -05:00
Kevin Brown
7d8f86cbf8 Add tests for removing a selection when disabled
These tests should fail because a selection can be removed even
though the container is disabled. This is because the only thing
preventing selections from being removed was the CSS which hid the
remove buttons when the container was disabled.
2015-08-19 20:59:39 -04:00
Kevin Brown
dd2990adea Skip focus test on IE 8
I can't reproduce this test failure on and IE 8 virtual machine, so
I'm just going to skip it on IE 8.
2015-08-09 21:00:48 -04:00
Kevin Brown
88503d2c67 Add test for 698fe7b
This adds the test that ensures that the search focus is still
focused, even after the selection is updated (for whatever reason).
Note that we are not triggering the `change` event here, and are
instead just re-calling `update` on the selection adapter. This is
because we do not bind the `change` event in tests, so the selection
is never re-rendered and the tests will pass. The `update` method
is triggered during the `change` cycle anyway, so this has the
same effect while supporting cases where the selection is re-rendered
without the selected values changing.
2015-06-21 21:42:06 -04:00
Stretch
e60ab22a85 Adding single select support and testing 2015-06-10 20:05:07 +10:00
Stretch
581af39288 #3222 test cleanup
Improving my test from feedback.
2015-05-08 08:03:46 +10:00
Stretch
13cead0bd0 Adding container support #3222
Fixes issue #3222
Now templateSelection can have access to the parent container so that
classes can be added for styling
2015-05-07 21:59:51 +10:00
Kevin Brown
f3f1b31958 Add back *css* options through an adapter
The old functionality where classes were directly copied to the
container can be done by setting `dropdownCssClass: ':all:'` when
initializing Select2.

This closes https://github.com/select2/select2/issues/2879.
2015-04-05 21:58:02 -04:00
Kevin Brown
b9b55cec44 Tests use jQuery 1.7.2
As jQuery 1.7.2 is the lowest version of jQuery supported by Select2,
it makes sense to run the tests on it. For the most part, we can
assume that the newer versions of Select2 are backwards compatible
enough such that this isn't an issue.

The recommended version of jQuery to use is the latest though, which
is why the jQuery file is only included in the tests.

This revealed a few issues with our data fallbacks and `.append`
functionality that was introduced in jQuery 1.8.
2015-03-11 19:20:41 -04:00
Kevin Brown
72e5c2a50d Combine tests into common files
This groups tests into common HTML files so they can be run more
quickly. This also reduces the number of Sauce Labs instances that
have to be run, as one instance was previously spun up for each
file.
2015-02-13 23:29:56 -05:00
Kevin Brown
8f8140e3b0 Added modules for stopping event propagation
This adds `StopPropagation` modules that will stop the propagation
of the most common events from the selection and dropdown containers.
These modules work from a list of 21 common events, most of which
were stopped by default in past versions, and call `stopPropagation`
on them when they are detected at the container level.

These modules are only available in full builds of Select2.

This closes https://github.com/select2/select2/issues/2033.
This closes https://github.com/select2/select2/issues/2974.
2015-02-09 20:04:01 -05:00
Kevin Brown
4dda5e7a74 Hide the search clear icon in webkit
The search box previously displayed a clear icon on the far right
side in webkit-based browsers, specifically Chrome and Safari. This
hides the clear icon in those browsers, and also fixes a slight
sizing issue, so it should no longer be displayed.

This also disables autocorrect, autocompleted, as well as a few
other automatic search corrections on the field, so mobile devices
should have a better experience.

This closes https://github.com/select2/select2/issues/3018.
2015-02-09 15:29:28 -05:00
Kevin Brown
5a0f7f5518 Added back escapeMarkup
This is needed to escape any bad markup that is passed through
user-entered data. Users can prevent their markup from being
escaped by using a no-op `escapeMarkup` function.

This closes https://github.com/select2/select2/issues/2990.
2015-01-29 09:15:02 -05:00
Kevin Brown
686f846fa5 Changed how the builds are done
This adds a check that triggers an error if Select2 was not able
to detect a copy of jQuery on the page. This should help users when
they are setting up Select2.

**Breaking change:** The full build no longer includes jQuery.
Previously, the full build included all requirements for Select2,
including jQuery, which meant that anyone looking for the optional
requirements had to possibly include multiple versions of jQuery
on their page. This means that anyone requiring Select2 to also
bundle jQuery will now need to include jQuery on their pages
alongside Select2. A copy of jQuery is included in the repository.

**Breaking change:** The AMD build of Select2 will now correctly
wrap the code in a `define` block. It will still create the named
blocks inside of the code, which should be valid in most AMD build
systems, so now Select2 is compatible with cases where the file
does not have the same name as the Select2 module name.

**Breaking change:** Select2 will re-use the AMD methods if they
are available on the page, but it will not longer leak the included
AMD loader to the global scope. The AMD methods will still be
available on the `jQuery.fn.select2.amd` namespace.

The `mock.js` test file has been renamed to `helpers.js` and will
handle the escalation of the `require` and `define` variables to
the global scope. It should be included in all test files, or the
tests will fail.

This closes https://github.com/select2/select2/issues/2946.
2015-01-22 14:49:39 -05:00
Kevin Brown
d81886e5de Trigger the unselect event when clearing placeholder
In the past, Select2 triggered the `select2-clearing` event when
clearing the placeholder. This has been switched to the `unselect`
event which is now triggered whenever the placeholder is cleared.
The placeholder can also be prevented if the `unselecting` event
is prevented.

This will also trigger the event when deleting every option from
the multiple select, so it is possible for the `unselecting` event
to be triggered multiple times when clearing a multiple select.

This adds tests to ensure that the `allowClear` option always works.

This closes https://github.com/select2/select2/issues/2954.
2015-01-21 19:11:07 -05:00
Kevin Brown
024d41b412 Normalize internal select/unselect events
Also pull the logic for automatically closing the dropdown into the
dropdown adapter, taking it out of the core.

The `selected` and `unselected` events are now `select` and
`unselect`, which is what many of the other adapters were expecting
them to be.

Some tests for placeholders have been added.
2015-01-09 10:05:44 -05:00
Kevin Brown
43efd43d57 Add tests for the multiple selection container 2014-11-26 20:50:39 -05:00
Kevin Brown
4cab421966 Added tests for the single selection container 2014-11-26 20:25:56 -05:00