diff --git a/CHANGELOG.md b/CHANGELOG.md index 31bc51949..176a4b24f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,88 +1,91 @@ + ## v0.13.7 · -* Fixed missing style for dropdown_header plugin [*@fabienwnklr*](https://github.com/fabienwnklr) -* Fixed ([#1818](https://github.com/selectize/selectize.js/issues/1818)) Scroll left when I click on a selectized item and page is scrolled right [*@fabienwnklr*](https://github.com/fabienwnklr) +- Fixed missing style for dropdown_header plugin [_@fabienwnklr_](https://github.com/fabienwnklr) +- Fixed ([#1818](https://github.com/selectize/selectize.js/issues/1818)) Scroll left when I click on a selectized item and page is scrolled right [_@fabienwnklr_](https://github.com/fabienwnklr) +- Added option to enable setting the first option in the list as active. + _@joshuan92_ ## v0.13.0 · 03 11 2020 -* Support for Bootstrap v4.x. - * Adding SASS styles, LESS styles still available for bootstrap 2.x -* Fixed bug (#851) for placeholder text clipping -* Fixed bug (#870) for remove button plugin closing bootstrap modals +- Support for Bootstrap v4.x. + - Adding SASS styles, LESS styles still available for bootstrap 2.x +- Fixed bug (#851) for placeholder text clipping +- Fixed bug (#870) for remove button plugin closing bootstrap modals - *@risadams* + _@risadams_ ## v0.12.4, v0.12.5 · 27 June 2018 -* Allow the dropdown to reopen on click if it is closed without losing focus - by closeAfterSelect: true - - *@fishpercolator* +- Allow the dropdown to reopen on click if it is closed without losing focus + by closeAfterSelect: true + _@fishpercolator_ -* Fixed bug making `clearOptions` function. Now it doesn't remove already selected options. +- Fixed bug making `clearOptions` function. Now it doesn't remove already selected options. - *(thanks @caseymct - #1079)* + _(thanks @caseymct - #1079)_ -* New feature: allow to disable single options or complete optgroups +- New feature: allow to disable single options or complete optgroups - *@zeitiger* + _@zeitiger_ ## v0.12.3 · 24 August 2016 -* Make `label[for]` work after applying Selectize (#755) - *Barrett Sonntag* (@barretts) +- Make `label[for]` work after applying Selectize (#755) -* Output friendly error message when Microplguin is missing (#1137). - Special thanks to @styxxx for proposing the improvement. + _Barrett Sonntag_ (@barretts) -* Add local server command `grunt server`. +- Output friendly error message when Microplguin is missing (#1137). + Special thanks to @styxxx for proposing the improvement. -* Stop creating items automatically when text is pasted, only create - them when pasted text contains delimiter. +- Add local server command `grunt server`. -* Fix regression 'Required fields can not be focusable' in Chrome - (#733) +- Stop creating items automatically when text is pasted, only create + them when pasted text contains delimiter. -* Fix detection of Validity API, we had false negatives before. +- Fix regression 'Required fields can not be focusable' in Chrome + (#733) - *Jonathan Allard* (@joallard) +- Fix detection of Validity API, we had false negatives before. -* Fix open keyboard bug under iOS after closing selection (#1127) + _Jonathan Allard_ (@joallard) - *@zeitiger* +- Fix open keyboard bug under iOS after closing selection (#1127) -* Fix highlighting more than one character (#1099, #1098) + _@zeitiger_ - *@skimi* +- Fix highlighting more than one character (#1099, #1098) + _@skimi_ ## v0.12.2 · 23 June 2016 -* Fix issue preventing build ("Cannot assign to read only property - 'subarray'") because of bug in uglifyjs. (#1072) - *@jaridmargolin* +- Fix issue preventing build ("Cannot assign to read only property + 'subarray'") because of bug in uglifyjs. (#1072) + + _@jaridmargolin_ -* Fix tabbing issue (#877) on IE11. (#997) +- Fix tabbing issue (#877) on IE11. (#997) - *@bwilson-ux* + _@bwilson-ux_ -* Fix jQuery initialization for jQuery >= 1.9 (#1045) +- Fix jQuery initialization for jQuery >= 1.9 (#1045) - *@mpokrywka* + _@mpokrywka_ -* Make `remove_button` work for single-option usage (#848) +- Make `remove_button` work for single-option usage (#848) - *@ChoppyThing* + _@ChoppyThing_ -* Fixed bug that made `allowEmptyOption: true` useless (#739) +- Fixed bug that made `allowEmptyOption: true` useless (#739) - *@mcavalletto* + _@mcavalletto_ -* Functions in option `render` can now return a DOM node in addition to - text. (#617) +- Functions in option `render` can now return a DOM node in addition to + text. (#617) - *@topaxi* + _@topaxi_ diff --git a/docs/usage.md b/docs/usage.md index 3b89900d4..7829656b9 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -4,9 +4,9 @@ ``` @@ -23,464 +23,470 @@ $(function() { ### Configuration - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
General
SettingDescriptionTypeDefault
options - An array of the initial options available to select; array - of objects. - By default this is populated from the original input - element. If your element is a <select> with - <option>s specified this property gets populated - automatically. - Setting this property is convenient if you have your data as - an array and want to automatically generate the - <option>s. - array[]
itemsAn array of the initial selected values. By default this is populated from the original input element.array[]
delimiterThe string to separate items by. When typing an item in a multi-selection control allowing creation, then the delimiter, the item is added. If you paste delimiter-separated items in such control, the items are added at once. The delimiter is also used in the getValue API call on a text <input> tag to separate the multiple values.string','
create - Allows the user to create new items that aren't in the - initial list of options. This setting can be any of the - following: true, false (disabled), or a function to - process input. The function can take one of two forms: - synchronous (with signature function(input){} - or asynchronous (with signature function(input, - callback). In the synchronous case, the function - should return an object for the options (eg, - with defaults: return { 'value': value, 'text': text - };). The asynchronous version should invoke the - callback with the result in the same format as the object - above (eg, callback( { 'value': value, 'text': - text});)boolean/functionfalse
showAddOptionOnCreateToggles whether to show 'Add ...option...' within the dropdown menu (if create setting is enabled). booleantrue
createOnBlur - If true, when user exits the field (clicks outside of input), a new option is created and selected (if create setting is enabled). - booleanfalse
createFilter - Specifies a RegExp or a string containing a regular expression that the current search filter must match to be allowed to be created. May also be a predicate function that takes the filter text and returns whether it is allowed.RegExp|string|functionnull
highlightToggles match highlighting within the dropdown menu.booleantrue
persistIf false, items created by the user will not show up as available options once they are unselected.booleantrue
openOnFocusShow the dropdown immediately when the control receives focus.booleantrue
maxOptionsThe max number of items to render at once in the dropdown list of options.int1000
maxItemsThe max number of items the user can select. 1 makes the control mono-selection, null allows an unlimited number of items.intnull
hideSelectedIf true, the items that are currently selected will not be shown in the dropdown list of available options. This defaults to true when in a multi-selection control, to false otherwise.booleannull
closeAfterSelectIf true, the dropdown will be closed after a selection is made.booleanfalse
closeDropdownThresholdThe number of milliseconds to throttle the opening of the dropdown after it is closed by clicking on the control. Setting this to 0 will reopen the dropdown after clicking on the control when the dropdown is open. This does not affect multi-selects.int250
allowEmptyOptionIf true, Selectize will treat any options with a "" value like normal. This defaults to false to accomodate the common <select> practice of having the first empty option to act as a placeholder.booleanfalse
showEmptyOptionInDropdownIf true, Selectize will show an option with value `""` in dropdown, if one does not exist; which is required when you want to select a empty option via `selectOnTab`. This requires `allowEmptyOption: true`.booleanfalse
emptyOptionLabelIf `showEmptyOptionInDropdown: true` and an option with value `""` in dropdown does not exist, an option with `""` value is created, the label/text of the option can be set via this option, this requires `showEmptyOptionInDropdown: true`.string'--'
scrollDurationThe animation duration (in milliseconds) of the scroll animation triggered when going [up] and [down] in the options dropdown.int60
deselectBehaviorIf an option is selected, the same option is highlighted/marked active in the dropdown, pressing backspace on the input control removes the option and in dropdown the previous element is highlight. When this option is set to `top` it shifts the highlight to the topmost option. Valid options are `top` and `previous`.stringprevious
loadThrottleThe number of milliseconds to wait before requesting options from the server or null. If null, throttling is disabled. Useful when loading options dynamically while the user types a search / filter expression.int300
loadingClassThe class name added to the wrapper element while awaiting the fulfillment of load requests.string'loading'
placeholderThe placeholder of the control (displayed when nothing is selected / typed). Defaults to input element's placeholder, unless this one is specified.stringundefined
preloadIf true, the load function will be called upon control initialization (with an empty search). Alternatively it can be set to 'focus' to call the load function when control receives focus.boolean/stringfalse
dropdownParentThe element the dropdown menu is appended to. This should be 'body' or null. If null, the dropdown will be appended as a child of the Selectize control.stringnull
addPrecedenceIf true, the "Add..." option is the default selection in the dropdown.booleanfalse
selectOnTabIf true, the tab key will choose the currently selected item.booleanfalse
diacriticsEnable or disable international character support.booleantrue
Data / Searching
SettingDescriptionTypeDefault
optionsSee abovearray[]
optgroups - Option groups that options will be bucketed into. If your - element is a <select> with <optgroup>s this - property gets populated automatically. Make sure each object - in the array has a property named whatever - optgroupValueField is set to. - array[]
dataAttrThe <option> attribute from which to read JSON data about the option.string'data-data'
valueFieldThe name of the property to use as the value when an item is selected.string'value'
optgroupValueFieldThe name of the option group property that serves as its unique identifier.string'value'
labelFieldThe name of the property to render as an option / item label (not needed when custom rendering functions are defined).string'text'
optgroupLabelFieldThe name of the property to render as an option group label (not needed when custom rendering functions are defined).string'label'
optgroupFieldThe name of the property to group items by.string'optgroup'
disabledFieldThe name of the property to disabled option and optgroup.string'disabled'
sortField -

A single field or an array of fields to sort by. Each item in the array should be an object containing at least a field property. Optionally, direction can be set to 'asc' or 'desc'. The order of the array defines the sort precedence.

-

Unless present, a special `$score` field will be automatically added to the beginning of the sort list. This will make results sorted primarily by match quality (descending).

-

You can override the `$score` function. For more information, see the sifter documentation.

-
string|array'$order'
searchFieldAn array of property names to analyze when filtering options.array['text']
searchConjunctionWhen searching for multiple terms (separated by space), this is the operator used. Can be 'and' or 'or' .string'and'
General
SettingDescriptionTypeDefault
options + An array of the initial options available to select; array + of objects. + By default this is populated from the original input + element. If your element is a <select> with + <option>s specified this property gets populated + automatically. + Setting this property is convenient if you have your data as + an array and want to automatically generate the + <option>s. + array[]
itemsAn array of the initial selected values. By default this is populated from the original input element.array[]
delimiterThe string to separate items by. When typing an item in a multi-selection control allowing creation, then the delimiter, the item is added. If you paste delimiter-separated items in such control, the items are added at once. The delimiter is also used in the getValue API call on a text <input> tag to separate the multiple values.string','
create + Allows the user to create new items that aren't in the + initial list of options. This setting can be any of the + following: true, false (disabled), or a function to + process input. The function can take one of two forms: + synchronous (with signature function(input){} + or asynchronous (with signature function(input, + callback). In the synchronous case, the function + should return an object for the options (eg, + with defaults: return { 'value': value, 'text': text + };). The asynchronous version should invoke the + callback with the result in the same format as the object + above (eg, callback( { 'value': value, 'text': + text});)boolean/functionfalse
showAddOptionOnCreateToggles whether to show 'Add ...option...' within the dropdown menu (if create setting is enabled). booleantrue
createOnBlur + If true, when user exits the field (clicks outside of input), a new option is created and selected (if create setting is enabled). + booleanfalse
createFilter + Specifies a RegExp or a string containing a regular expression that the current search filter must match to be allowed to be created. May also be a predicate function that takes the filter text and returns whether it is allowed.RegExp|string|functionnull
highlightToggles match highlighting within the dropdown menu.booleantrue
persistIf false, items created by the user will not show up as available options once they are unselected.booleantrue
openOnFocusShow the dropdown immediately when the control receives focus.booleantrue
maxOptionsThe max number of items to render at once in the dropdown list of options.int1000
maxItemsThe max number of items the user can select. 1 makes the control mono-selection, null allows an unlimited number of items.intnull
hideSelectedIf true, the items that are currently selected will not be shown in the dropdown list of available options. This defaults to true when in a multi-selection control, to false otherwise.booleannull
closeAfterSelectIf true, the dropdown will be closed after a selection is made.booleanfalse
closeDropdownThresholdThe number of milliseconds to throttle the opening of the dropdown after it is closed by clicking on the control. Setting this to 0 will reopen the dropdown after clicking on the control when the dropdown is open. This does not affect multi-selects.int250
allowEmptyOptionIf true, Selectize will treat any options with a "" value like normal. This defaults to false to accomodate the common <select> practice of having the first empty option to act as a placeholder.booleanfalse
showEmptyOptionInDropdownIf true, Selectize will show an option with value `""` in dropdown, if one does not exist; which is required when you want to select a empty option via `selectOnTab`. This requires `allowEmptyOption: true`.booleanfalse
emptyOptionLabelIf `showEmptyOptionInDropdown: true` and an option with value `""` in dropdown does not exist, an option with `""` value is created, the label/text of the option can be set via this option, this requires `showEmptyOptionInDropdown: true`.string'--'
scrollDurationThe animation duration (in milliseconds) of the scroll animation triggered when going [up] and [down] in the options dropdown.int60
deselectBehaviorIf an option is selected, the same option is highlighted/marked active in the dropdown, pressing backspace on the input control removes the option and in dropdown the previous element is highlight. When this option is set to `top` it shifts the highlight to the topmost option. Valid options are `top` and `previous`.stringprevious
loadThrottleThe number of milliseconds to wait before requesting options from the server or null. If null, throttling is disabled. Useful when loading options dynamically while the user types a search / filter expression.int300
loadingClassThe class name added to the wrapper element while awaiting the fulfillment of load requests.string'loading'
placeholderThe placeholder of the control (displayed when nothing is selected / typed). Defaults to input element's placeholder, unless this one is specified.stringundefined
preloadIf true, the load function will be called upon control initialization (with an empty search). Alternatively it can be set to 'focus' to call the load function when control receives focus.boolean/stringfalse
dropdownParentThe element the dropdown menu is appended to. This should be 'body' or null. If null, the dropdown will be appended as a child of the Selectize control.stringnull
addPrecedenceIf true, the "Add..." option is the default selection in the dropdown.booleanfalse
selectOnTabIf true, the tab key will choose the currently selected item.booleanfalse
diacriticsEnable or disable international character support.booleantrue
setFirstOptionActiveEnable setting the first option in the list as active.booleanfalse
Data / Searching
SettingDescriptionTypeDefault
optionsSee abovearray[]
optgroups + Option groups that options will be bucketed into. If your + element is a <select> with <optgroup>s this + property gets populated automatically. Make sure each object + in the array has a property named whatever + optgroupValueField is set to. + array[]
dataAttrThe <option> attribute from which to read JSON data about the option.string'data-data'
valueFieldThe name of the property to use as the value when an item is selected.string'value'
optgroupValueFieldThe name of the option group property that serves as its unique identifier.string'value'
labelFieldThe name of the property to render as an option / item label (not needed when custom rendering functions are defined).string'text'
optgroupLabelFieldThe name of the property to render as an option group label (not needed when custom rendering functions are defined).string'label'
optgroupFieldThe name of the property to group items by.string'optgroup'
disabledFieldThe name of the property to disabled option and optgroup.string'disabled'
sortField +

A single field or an array of fields to sort by. Each item in the array should be an object containing at least a field property. Optionally, direction can be set to 'asc' or 'desc'. The order of the array defines the sort precedence.

+

Unless present, a special `$score` field will be automatically added to the beginning of the sort list. This will make results sorted primarily by match quality (descending).

+

You can override the `$score` function. For more information, see the sifter documentation.

+
string|array'$order'
searchFieldAn array of property names to analyze when filtering options.array['text']
searchConjunctionWhen searching for multiple terms (separated by space), this is the operator used. Can be 'and' or 'or' .string'and'
nesting If true, nested fields will be available for search using dot-notation to reference them (e.g. nested.property). *Warning: can reduce performance.* boolean false
lockOptgroupOrderIf truthy, Selectize will make all optgroups be in the same order as they were added (by the `$order` property). Otherwise, it will order based on the score of the results in each.booleanfalse
copyClassesToDropdownCopy the original input classes to the dropdown element.booleantrue
Callbacks
SettingDescriptionTypeDefault
load(query, callback)Invoked when new options should be loaded from the server. Called with the current query string and a callback function to call with the results when they are loaded (or nothing when an error arises).functionnull
score(search)Overrides the scoring function used to sort available options. The provided function should return a function that returns a number greater than or equal to zero to represent the score of an item (the function's first argument). If 0, the option is declared not a match. The search argument is a Search object. For an example, see the "GitHub" example.functionnull
formatValueToKey(key)Function to generate key for a new item created from input when create is set to true, to generate a `'key' => 'value'` combination. Without using this function, it will result in `'value' => 'value'` combination. The provided function should return a key that is not object or function.stringnull
onInitialize()Invoked once the control is completely initialized.functionnull
onFocus()Invoked when the control gains focus.functionnull
onBlur()Invoked when the control loses focus.functionnull
onChange(value)Invoked when the value of the control changes.functionnull
onItemAdd(value, $item)Invoked when an item is selected.functionnull
onItemRemove(value)Invoked when an item is deselected.functionnull
onClear()Invoked when the control is manually cleared via the clear() method.functionnull
onDelete(values)Invoked when the user attempts to delete the current selection.functionnull
onOptionAdd(value, data)Invoked when a new option is added to the available options list.functionnull
onOptionRemove(value)Invoked when an option is removed from the available options.functionnull
onDropdownOpen($dropdown)Invoked when the dropdown opens.functionnull
onDropdownClose($dropdown)Invoked when the dropdown closes.functionnull
onType(str)Invoked when the user types while filtering options.functionnull
onLoad(data)Invoked when new options have been loaded and added to the control (via the load option or load API method).functionnull
Rendering
render - Custom rendering functions. Each function should accept two - arguments: data and escape and return HTML (string - or DOM element) with a single root element. - The escape argument is a function that takes a string and - escapes all special HTML characters. - This is very important to use to prevent XSS vulnerabilities. - - - - - - - - - - - - - - - - - - - - - -
optionAn option in the
dropdown list of
available options.
itemAn item the user has
selected.
option_createThe "create new" option
at the bottom of the
dropdown. The data
contains one property :
input (which is
what the user has
typed).
optgroup_headerThe header of an option
group.
optgroupThe wrapper for an
optgroup. The html
property in the data
html of the optgroup's
header and options.
-
object
lockOptgroupOrderIf truthy, Selectize will make all optgroups be in the same order as they were added (by the `$order` property). Otherwise, it will order based on the score of the results in each.booleanfalse
copyClassesToDropdownCopy the original input classes to the dropdown element.booleantrue
Callbacks
SettingDescriptionTypeDefault
load(query, callback)Invoked when new options should be loaded from the server. Called with the current query string and a callback function to call with the results when they are loaded (or nothing when an error arises).functionnull
score(search)Overrides the scoring function used to sort available options. The provided function should return a function that returns a number greater than or equal to zero to represent the score of an item (the function's first argument). If 0, the option is declared not a match. The search argument is a Search object. For an example, see the "GitHub" example.functionnull
formatValueToKey(key)Function to generate key for a new item created from input when create is set to true, to generate a `'key' => 'value'` combination. Without using this function, it will result in `'value' => 'value'` combination. The provided function should return a key that is not object or function.stringnull
onInitialize()Invoked once the control is completely initialized.functionnull
onFocus()Invoked when the control gains focus.functionnull
onBlur()Invoked when the control loses focus.functionnull
onChange(value)Invoked when the value of the control changes.functionnull
onItemAdd(value, $item)Invoked when an item is selected.functionnull
onItemRemove(value)Invoked when an item is deselected.functionnull
onClear()Invoked when the control is manually cleared via the clear() method.functionnull
onDelete(values)Invoked when the user attempts to delete the current selection.functionnull
onOptionAdd(value, data)Invoked when a new option is added to the available options list.functionnull
onOptionRemove(value)Invoked when an option is removed from the available options.functionnull
onDropdownOpen($dropdown)Invoked when the dropdown opens.functionnull
onDropdownClose($dropdown)Invoked when the dropdown closes.functionnull
onType(str)Invoked when the user types while filtering options.functionnull
onLoad(data)Invoked when new options have been loaded and added to the control (via the load option or load API method).functionnull
Rendering
render + Custom rendering functions. Each function should accept two + arguments: data and escape and return HTML (string + or DOM element) with a single root element. + The escape argument is a function that takes a string and + escapes all special HTML characters. + This is very important to use to prevent XSS vulnerabilities. + + + + + + + + + + + + + + + + + + + + + +
optionAn option in the
dropdown list of
available options.
itemAn item the user has
selected.
option_createThe "create new" option
at the bottom of the
dropdown. The data
contains one property :
input (which is
what the user has
typed).
optgroup_headerThe header of an option
group.
optgroupThe wrapper for an
optgroup. The html
property in the data
html of the optgroup's
header and options.
+
object
diff --git a/index.d.ts b/index.d.ts index 5da2d52b1..f199c924c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -261,6 +261,13 @@ declare namespace Selectize { */ copyClassesToDropdown?: boolean; + /** + * Sets always the first option in the list as active. + * + * Default: false + */ + setFirstOptionActive?: boolean; + // Callbacks // ------------------------------------------------------------------------------------------------------------ diff --git a/package-lock.json b/package-lock.json index b5ac191b9..f80da839e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,7 +47,7 @@ "load-grunt-tasks": "^5.1.0", "mocha": "9.2.2", "popper.js": "1.16.1", - "sass": "1.54.9" + "sass": "1.55.0" }, "engines": { "node": "*" @@ -8571,9 +8571,9 @@ "dev": true }, "node_modules/sass": { - "version": "1.54.9", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.54.9.tgz", - "integrity": "sha512-xb1hjASzEH+0L0WI9oFjqhRi51t/gagWnxLiwUNMltA0Ab6jIDkAacgKiGYKM9Jhy109osM7woEEai6SXeJo5Q==", + "version": "1.55.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.55.0.tgz", + "integrity": "sha512-Pk+PMy7OGLs9WaxZGJMn7S96dvlyVBwwtToX895WmCpAOr5YiJYEUJfiJidMuKb613z2xNWcXCHEuOvjZbqC6A==", "dev": true, "dependencies": { "chokidar": ">=3.0.0 <4.0.0", @@ -17277,9 +17277,9 @@ "dev": true }, "sass": { - "version": "1.54.9", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.54.9.tgz", - "integrity": "sha512-xb1hjASzEH+0L0WI9oFjqhRi51t/gagWnxLiwUNMltA0Ab6jIDkAacgKiGYKM9Jhy109osM7woEEai6SXeJo5Q==", + "version": "1.55.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.55.0.tgz", + "integrity": "sha512-Pk+PMy7OGLs9WaxZGJMn7S96dvlyVBwwtToX895WmCpAOr5YiJYEUJfiJidMuKb613z2xNWcXCHEuOvjZbqC6A==", "dev": true, "requires": { "chokidar": ">=3.0.0 <4.0.0", diff --git a/package.json b/package.json index 4dd492232..11a8a5803 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "load-grunt-tasks": "^5.1.0", "mocha": "9.2.2", "popper.js": "1.16.1", - "sass": "1.54.9" + "sass": "1.55.0" }, "optionalDependencies": { "jquery-ui": "^1.13.2" diff --git a/src/defaults.js b/src/defaults.js index f7d02d49c..0c7560022 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -23,6 +23,7 @@ Selectize.defaults = { allowEmptyOption: false, showEmptyOptionInDropdown: false, emptyOptionLabel: '--', + setFirstOptionActive: false, closeAfterSelect: false, closeDropdownThreshold: 250, // number of ms to prevent reopening of dropdown after mousedown diff --git a/src/selectize.js b/src/selectize.js index f126c77aa..0d1565bcb 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -1221,22 +1221,24 @@ $.extend(Selectize.prototype, { } // activate - self.hasOptions = results.items.length > 0 || ( has_create_option && self.settings.showAddOptionOnCreate ); + self.hasOptions = results.items.length > 0 || ( has_create_option && self.settings.showAddOptionOnCreate ) || self.settings.setFirstOptionActive; if (self.hasOptions) { - if (results.items.length > 0) { - $active_before = active_before && self.getOption(active_before); - if (results.query !== "" && $active_before && $active_before.length) { - $active = $active_before; - } else if (self.settings.mode === 'single' && self.items.length) { - $active = self.getOption(self.items[0]); - } - if (!$active || !$active.length) { - if ($create && !self.settings.addPrecedence) { - $active = self.getAdjacentOption($create, 1); - } else { - $active = $dropdown_content.find('[data-selectable]:first'); - } - } + if (results.items.length > 0) { + $active_before = active_before && self.getOption(active_before); + if (results.query !== "" && self.settings.setFirstOptionActive) { + $active = $dropdown_content.find('[data-selectable]:first') + } else if (results.query !== "" && $active_before && $active_before.length) { + $active = $active_before; + } else if (self.settings.mode === 'single' && self.items.length) { + $active = self.getOption(self.items[0]); + } + if (!$active || !$active.length) { + if ($create && !self.settings.addPrecedence) { + $active = self.getAdjacentOption($create, 1); + } else { + $active = $dropdown_content.find('[data-selectable]:first'); + } + } } else { $active = $create; }