When Select2 is not used with a design that universally sets
`box-sizing: border-box` to elements, the search box previously
would take up more space than expected. This fixed the issue by
adding the `box-sizing` rule to the search box.
This closes https://github.com/select2/select2/issues/2978.
When we re-implemented support for responsive widths, through the
use of percentages, we never moved the support over to the dropdowns.
So the dropdowns generally were not large enough, and when resized
they never re-adjusted, and they didn't fully work as intended.
This fixes the issue by automatically resizing the dropdown whenever
it is repositioned, mainly to handle new scrollbars, which will
ensure that it is always the same width as the container.
This also adds a section to the examples for responsive design,
just like in the old documentation.
This closes https://github.com/select2/select2/issues/2949.
This reverts the changes (from 3.5.x) to the scroll detection, so
Select2 will still reposition itself every time the window is
scrolled or resized. This has the benefit of fixing the issue when
the screen jumps if the dropdown is too high, which would previously
close the dropdown.
Select2 will also correctly set the positioning if it is pushed out
of the top of the viewport. Due to an unexpected bug, Select2 would
previously still display above the container, but would be styled
as if it were below it.
This closes https://github.com/select2/select2/issues/2961.
This closes https://github.com/select2/select2/issues/2956.
This fixes an issue where an `unselect` event would be incorrectly
triggered when the selected option was selected again in a single
select. This has been fixed now, so the even will only be triggered
for multiple selects. The `close` event will still be triggered
though, so the functionality will still remain the same to the user.
This closes https://github.com/select2/select2/issues/2959.
The `selectOnClose` option did not work in production because we
were decorating the `dropdownAdapter` instead of the `resultsAdpater`
when automatically generating the adapters. This has now been fixed,
and the option should work without errors in production.
This also adds documentation for the `selectOnClose` option.
This closes https://github.com/select2/select2/issues/2953.
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.
When `jQuery.noConflict` is called, the global `$` variable is not
defined. We cannot assume in the code that the variable is defined,
and instead should always make sure to import the `jquery` module
when we need jQuery.
This fixes all of the issues where we are assuming that `$` is
defined globally when we are not importing the module. This also
fixes the issues when defining the `jQuery.fn.select2.amd` modules
where we were always attaching to the `$` object instead of the
`jQuery` object.
This closes https://github.com/select2/select2/issues/2947.
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.
This should prevent users from running into unexpected errors when
they do not return an object with the `results` key containing an
array.
This closes https://github.com/select2/select2/issues/2950.
If the language that is passed in through the options is just a
string, like "en-US" or "pt-BR", Select2 will now try to load the
base language along with the requested language and "en". So
requesting "pt-BR" will try to load "pt-BR", "pt", and "en".
This also catches errors and triggers a warning about not being
able to load the file. This should be a more user friendly error,
and it fixes the problem where Select2 would completely fail to
initialize if a language could not be found.
This closes https://github.com/select2/select2/issues/2934.
Previously this would return `style` if it couldn't be resolved and
the `style` attribute on the element is set for some reason. Now it
will return `null`, because it tried to resolve the width but was
not able to. This will allow it to fall back to `element` by default,
or not set the width at all.
This closes https://github.com/select2/select2/issues/2935.
This exposes the default options for Select2 as
`$.fn.select2.defaults`. A default option can be set using the
`set(key, val)` option which is available. The key should use the
same formatting as the HTML data attributes.
This also adds some documentation about it.
This also adds more documentation and corrects the release notes
for these breaking changes. These modules will now only be included
in the full builds of Select2, which has been noted in a few places.
This adds basic tests to ensure that the selection is accessible by
all users. This checks for common attributes, ensuring that the
container is always keyboard accessible and follows ARIA guidelines.
This also changes the base selection to create a common element so
we don't need to repeat attributes and such across multiple selection
containers.
This adds backwards compatibility with the `query` option so it
automatically patches the `DataAdapter.query` function. The only
major difference between the methods is the call signature, which
has now moved the callback out of the parameters and into the second
argument.
This also adds tests that verify that the old query functions should
work as expected.
Now if the old `initSelection` method is used, a warning will be
triggered in the console informing the user that it has now been
changed to `DataAdapter.current`, and they should create a custom
data adapter instead. We will still only call `initSelection` once,
and then default back to the old data adapter for calls after that.
This allows for mostly transparent support between versions.
This adds tests to ensure that `initSelection` operates the same as
it previously did, but now patches the `current` method of the
default data adapter.
This adds detailed docs explaining how you can convert the old
implementations of `query` and `initSelection` into a custom data
adapter using the `current` and `query` methods provided there.
Examples are included that should make it considerably easier to
handle.
This adds the `select` and `unselect` events so users can still
hook into them from their jQuery plugins.
This also modifies the core `trigger` to fire pre-events that can
be canceled for the `open`, `close`, `select`, and `unselect`
events. Users implementing these events who need to handle cases
where the event has been prevented should check `args.prevented`,
where `args` is the object that was included for arguments when
triggering the internal event.
This should allow those using their own build systems to
automatically load in translations. In the future, the `amdBase`
option may be used to optionally load some components of Select2.
As Select2 cannot know what the base directory is, it currently
has to load in all of the optional components in the default build.
By allowing users to set their own base, it will allow us to know
the base to load files from, which makes it easier to use the
`require` function to optionally load them.
This fixes https://github.com/select2/select2/issues/2899.
`selectOnClose` is a new option which works very much like the old
`selectOnBlur` option. When the `close` event is triggered, the
highlighted result is automatically selected. This is useful for
single selects, which is where it is designed to be used, but it
can also be used on multiple selects.
This also adds tests to verify that this works in the future.
During the creation of the test, we noticed that we were missing a
mock container that could be used for triggering events. One was
created and a general mock JS file was created to hold any future
mocks for tests.
In past versions of Select2, the `width` option could be used to
tell Select2 how to determine the width of the container generated
by Select2.
**Breaking change:** The default value for the `width` option has
been changed from `copy` to `resolve.`
**Breaking change:** The old option called `copy` has been renamed
to `style` to better reflect what the width is generated from.
This fixes https://github.com/select2/select2/pull/2090.
This fixes https://github.com/select2/select2/issues/2911.
While deep nesting will not work on a standard `<select>`, we can
emulate it through data objects still, and just handle the display
of the data in the results.
This also means that the horrific deep-nested CSS is back to handle
the padding. I hope that will get fixed over time.
This also fixes one of the performance issues with adding array
data, as options are added at the very end instead of one by one.
Due to a change in 7edf0e3ebe that
made the rendered selection take up the full width of the selection
container, the placeholder was not being automatically displayed.
The calculations were always turning out negative, which has been
fixed by not trying to automatically calculate the best possible
width.
Because of the change made previously to make events global, any
time a result message was triggered there would be a stack overflow.
This was because we were re-triggering the event locally if it
happened on a global level, which would start the loop.
This has been fixed so the event is never caught locally, but
instead uses the global handler.
The `AllowClear` decorator appears to work fine with multiple
selects, so we've chosen to remove remove it. This adds some
styling and fixes the check so it all works as expected.
This closes https://github.com/select2/select2/issues/2903.
This fixes an issue where the `x` in multiple selects (visible next
to the option) would be visible even if the container was disabled.
Because it was still accepting events as well, this would cause the
underlying data to be changed, even though it was disabled. We now
hide the icon using CSS so this issue doesn't occur.
The same applies to the `x` for clearing a placeholder.
https://github.com/select2/select2/issues/2903
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.
Now Select2 can fire jQuery events that will match the corresponding
internal events. The `open` and `close` events are now publicly
accessible.
The selection adapter was chosen because it is the least likely to
be moved, but handles the most common events. This `EventRelay`
decorator should theoretically be able to decorate any of the
adapters, as they all have the `bind` method that it needs.
The star event will allow us to relay any custom events as well as
the ones used internally by Select2. This also makes it much
easier to start triggering events in general, as we don't need to
relay it in the core anymore.
A module has been created for the jQuery-facing events, and the
release announcement has been updated to mention the event name
changes.
This also adds some documentation about the public events.
For the dropdown search on single select instances, the search
focus should happen in a `setTimeout` call. This is because many
browsers trigger the element focus on `click`, so our original call
to `$search.focus` will essentially be ignored. By also focusing
it in a timeout, this will delay the call to `focus` so the browser
will no longer take it back.
We do not have this issue for multiple select instances, as they
trigger the `open` event on `click`, instead of using `mousedown`.
This fixes https://github.com/select2/select2/issues/2900.
There was a plan to universally use an array as the return from
query methods, but now that we've realized pagination and extra
things are impossible without it, we're going back to the return
object. Anyone looking to migrate their data should be returning
an object with the key `results` containing what they previously
returned.
This should fix https://github.com/select2/select2/issues/2898
This fixes the SASS error caused by the `&[dir="rtl"]` selector in
the `_single.scss` and `_multiple.scss` files. We were expecting
these files to be nested within the `.select-container` class, which
would have made this a non-error as the `&` would refer to the
`.select2-container` class that was wrapping the `@import`.
This moves the `@import` statements into the `.select2-container`
class, so this no longer triggers an error in the Ruby version of
SASS.
This closes https://github.com/select2/select2/issues/2896
jQuery.mousewheel will allow us to prevent the dropdown from
automatically closing when the user scrolls to the end of the list.
It is automatically bundled in the full versions of Select2 and
we don't require that it is included in order for Select2 to work.
jQuery.mousewheel was taken directly from the source repository
using the commit at
cc2c5d73ae
I'm still not quite sure how this should be handled for the general
case, but for the special case we have this for infinite scrolling,
only on AJAX data.
This will always clone the options that are passed in when
initializing Select2 on multiple objects (like `$("select")`) so
it doesn't always assume that the configuration is the exact same.
This prevents any reference-based tricks for modifying the data
within Select2, but some would look at that as an upside.
The documentation for templates still needs to be created.
A warning is now generated in the console for applications using
the previous data attributes that have been migrated.