mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-08 17:02:33 +02:00
Merge branch 'master' into scope-mouse-down
This commit is contained in:
commit
6bc7973c3d
Binary file not shown.
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 44 KiB |
BIN
.github/actions-scripts/__snapshots__/puppeteer-darwin.png
vendored
Executable file → Normal file
BIN
.github/actions-scripts/__snapshots__/puppeteer-darwin.png
vendored
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 268 KiB |
21
.github/workflows/browsers.yml
vendored
21
.github/workflows/browsers.yml
vendored
|
@ -28,6 +28,8 @@ jobs:
|
||||||
browser: ie
|
browser: ie
|
||||||
- os: macOS-latest
|
- os: macOS-latest
|
||||||
browser: chrome
|
browser: chrome
|
||||||
|
# Safari workaround is not working in Catalina
|
||||||
|
- browser: safari
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -42,6 +44,17 @@ jobs:
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.x'
|
node-version: '12.x'
|
||||||
|
|
||||||
|
- name: Cache node modules
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.OS }}-build-${{ matrix.browser }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.OS }}-build-${{ env.cache-name }}-
|
||||||
|
${{ runner.OS }}-build-
|
||||||
|
${{ runner.OS }}-
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
@ -94,9 +107,13 @@ jobs:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
- uses: actions/setup-node@v1
|
- name: Cache node modules
|
||||||
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.x'
|
path: ~/.npm
|
||||||
|
key: ${{ runner.OS }}-build-puppeteer
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.OS }}-build-puppeteer
|
||||||
- run: |
|
- run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
|
55
.github/workflows/e2e-tests.yml
vendored
55
.github/workflows/e2e-tests.yml
vendored
|
@ -10,11 +10,15 @@ on:
|
||||||
- 'webpack.config.*'
|
- 'webpack.config.*'
|
||||||
- 'public/test/**'
|
- 'public/test/**'
|
||||||
- 'cypress/**'
|
- 'cypress/**'
|
||||||
- '.github/workflows/cypress.yml'
|
- '.github/workflows/e2e-tests.yml'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-e2e:
|
test-e2e:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
TERM: xterm-256color
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
with:
|
with:
|
||||||
|
@ -22,33 +26,42 @@ jobs:
|
||||||
|
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10
|
node-version: 12.x
|
||||||
|
|
||||||
|
- name: Cache node modules
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.OS }}-build-${{ env.cache-name }}-
|
||||||
|
${{ runner.OS }}-build-
|
||||||
|
${{ runner.OS }}-
|
||||||
|
|
||||||
|
- name: Get Cypress info
|
||||||
|
id: cypress-info
|
||||||
|
run: |
|
||||||
|
echo ::set-output name=version::$(jq -r .devDependencies.cypress ./package.json)
|
||||||
|
echo ::set-output name=cache::$(npx cypress cache path)
|
||||||
|
env:
|
||||||
|
CYPRESS_INSTALL_BINARY: 0
|
||||||
|
- name: Cache Cypress cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ steps.cypress-info.outputs.cache }}
|
||||||
|
key: ${{ runner.OS }}-cypress-${{ steps.cypress-info.outputs.version }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.OS }}-cypress-${{ steps.cypress-info.outputs.version }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
env:
|
env:
|
||||||
HUSKY_SKIP_INSTALL: true
|
HUSKY_SKIP_INSTALL: true
|
||||||
|
|
||||||
- name: run Cypress (with recording)
|
- name: run Cypress (with or without recording)
|
||||||
run: npx run-p --race start cypress:ci
|
# if we have ran out of free Cypress recordings, run Cypress with recording switched off
|
||||||
|
run: npx run-p --race start cypress:ci || npx run-p --race start cypress:run
|
||||||
env:
|
env:
|
||||||
CI: true
|
|
||||||
TERM: xterm-256color
|
|
||||||
NODE_ENV: production # prevent watching
|
|
||||||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
|
||||||
DEBUG: commit-info,cypress:server:record
|
|
||||||
# https://docs.cypress.io/guides/guides/continuous-integration.html#Environment-variables
|
|
||||||
COMMIT_INFO_BRANCH: ${{ github.head_ref }}
|
|
||||||
COMMIT_INFO_AUTHOR: ${{ github.event.sender.login }}
|
|
||||||
COMMIT_INFO_SHA: ${{ github.event.after }}
|
|
||||||
|
|
||||||
# if we have ran out of free Cypress recordings, run Cypress with recording switched off
|
|
||||||
- name: run Cypress (without recording)
|
|
||||||
if: failure()
|
|
||||||
run: npx run-p --race start cypress:run
|
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
TERM: xterm-256color
|
|
||||||
NODE_ENV: production # prevent watching
|
NODE_ENV: production # prevent watching
|
||||||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
||||||
DEBUG: commit-info,cypress:server:record
|
DEBUG: commit-info,cypress:server:record
|
||||||
|
|
|
@ -962,5 +962,41 @@ describe('Choices - select one', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('disabling first choice via options', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('[data-test-hook=disabled-first-choice-via-options]')
|
||||||
|
.find('.choices')
|
||||||
|
.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
let disabledValue;
|
||||||
|
|
||||||
|
it('disables the first choice', () => {
|
||||||
|
cy.get('[data-test-hook=disabled-first-choice-via-options]')
|
||||||
|
.find('.choices__list--dropdown .choices__list')
|
||||||
|
.children()
|
||||||
|
.first()
|
||||||
|
.should('have.class', 'choices__item--disabled')
|
||||||
|
.then($choice => {
|
||||||
|
disabledValue = $choice.val();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('selects the first enabled choice', () => {
|
||||||
|
cy.get('[data-test-hook=disabled-first-choice-via-options]')
|
||||||
|
.find('.choices__input[hidden]')
|
||||||
|
.then($option => {
|
||||||
|
expect($option.text().trim()).to.not.equal(disabledValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.get('[data-test-hook=disabled-first-choice-via-options]')
|
||||||
|
.find('.choices__item.choices__item--selectable')
|
||||||
|
.first()
|
||||||
|
.should($choice => {
|
||||||
|
expect($choice.text().trim()).to.not.equal(disabledValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -2956,9 +2956,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"cypress": {
|
"cypress": {
|
||||||
"version": "3.5.0",
|
"version": "3.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/cypress/-/cypress-3.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/cypress/-/cypress-3.6.0.tgz",
|
||||||
"integrity": "sha512-I1iSReD2C8CTP6s4BvQky4gEqHBnKLmhBIqFyCUZdj6BQ6ZDxGnmIbQPM5g79E2iP60KTIbTK99ZPSDVtsNUUg==",
|
"integrity": "sha512-ODhbOrH1XZx0DUoYmJSvOSbEQjycNOpFYe7jOnHkT1+sdsn2+uqwAjZ1x982q3H4R/5iZjpSd50gd/iw2bofzg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@cypress/listr-verbose-renderer": "0.4.1",
|
"@cypress/listr-verbose-renderer": "0.4.1",
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
"build": "run-p js:build css:build",
|
"build": "run-p js:build css:build",
|
||||||
"lint": "eslint src/scripts",
|
"lint": "eslint src/scripts",
|
||||||
"bundlesize": "bundlesize",
|
"bundlesize": "bundlesize",
|
||||||
"cypress:run": "$(npm bin)/cypress run",
|
"cypress:run": "cypress run",
|
||||||
"cypress:open": "$(npm bin)/cypress open",
|
"cypress:open": "cypress open",
|
||||||
"cypress:ci": "cypress run --record --group $GITHUB_REF --ci-build-id $GITHUB_SHA",
|
"cypress:ci": "cypress run --record --group $GITHUB_REF --ci-build-id $GITHUB_SHA",
|
||||||
"test": "run-s test:unit test:e2e",
|
"test": "run-s test:unit test:e2e",
|
||||||
"test:unit": "NODE_ENV=test mocha",
|
"test:unit": "NODE_ENV=test mocha",
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
"bundlesize": "^0.18.0",
|
"bundlesize": "^0.18.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"csso-cli": "^3.0.0",
|
"csso-cli": "^3.0.0",
|
||||||
"cypress": "3.5.0",
|
"cypress": "3.6.0",
|
||||||
"eslint": "^6.6.0",
|
"eslint": "^6.6.0",
|
||||||
"eslint-config-airbnb-base": "^14.0.0",
|
"eslint-config-airbnb-base": "^14.0.0",
|
||||||
"eslint-config-prettier": "^6.5.0",
|
"eslint-config-prettier": "^6.5.0",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<browserconfig>
|
<browserconfig>
|
||||||
<msapplication>
|
<msapplication>
|
||||||
<tile>
|
<tile>
|
||||||
<square150x150logo src="/assets/images/mstile-150x150.png"/>
|
<square150x150logo src="/assets/images/mstile-150x150.png"/>
|
||||||
<TileColor>#ffffff</TileColor>
|
<TileColor>#ffffff</TileColor>
|
||||||
</tile>
|
</tile>
|
||||||
</msapplication>
|
</msapplication>
|
||||||
</browserconfig>
|
</browserconfig>
|
||||||
|
|
|
@ -1372,8 +1372,8 @@ var getAdjacentEl = function getAdjacentEl(startEl, selector, direction) {
|
||||||
return sibling;
|
return sibling;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} element
|
* @param {Element} element
|
||||||
* @param {HTMLElement} parent
|
* @param {Element} parent
|
||||||
* @param {-1 | 1} direction
|
* @param {-1 | 1} direction
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
@ -1412,7 +1412,7 @@ var sanitise = function sanitise(value) {
|
||||||
return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/</g, '<').replace(/"/g, '"');
|
return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/</g, '<').replace(/"/g, '"');
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @returns {function}
|
* @returns {() => (str: string) => Element}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var strToEl = function () {
|
var strToEl = function () {
|
||||||
|
@ -1511,9 +1511,10 @@ var cloneObject = function cloneObject(obj) {
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
* Returns an array of keys present on the first but missing on the second object
|
||||||
* @param {object} a
|
* @param {object} a
|
||||||
* @param {object} b
|
* @param {object} b
|
||||||
* @returns {array}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var diff = function diff(a, b) {
|
var diff = function diff(a, b) {
|
||||||
|
@ -1621,14 +1622,14 @@ function () {
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get group by group id
|
* Get group by group id
|
||||||
* @param {string} id Group ID
|
* @param {number} id Group ID
|
||||||
* @returns {Group | undefined} Group data
|
* @returns {Group | undefined} Group data
|
||||||
*/
|
*/
|
||||||
;
|
;
|
||||||
|
|
||||||
_proto.getGroupById = function getGroupById(id) {
|
_proto.getGroupById = function getGroupById(id) {
|
||||||
return this.groups.find(function (group) {
|
return this.groups.find(function (group) {
|
||||||
return group.id === parseInt(id, 10);
|
return group.id === id;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2381,7 +2382,7 @@ function () {
|
||||||
this.element.innerHTML = '';
|
this.element.innerHTML = '';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {Element} node
|
* @param {Element | DocumentFragment} node
|
||||||
*/
|
*/
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -2410,7 +2411,7 @@ function () {
|
||||||
this.element.scrollTop = 0;
|
this.element.scrollTop = 0;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} element
|
* @param {Element} element
|
||||||
* @param {1 | -1} direction
|
* @param {1 | -1} direction
|
||||||
*/
|
*/
|
||||||
;
|
;
|
||||||
|
@ -3045,12 +3046,13 @@ var TEMPLATES =
|
||||||
/* harmony default export */ var templates = (TEMPLATES);
|
/* harmony default export */ var templates = (TEMPLATES);
|
||||||
// CONCATENATED MODULE: ./src/scripts/actions/choices.js
|
// CONCATENATED MODULE: ./src/scripts/actions/choices.js
|
||||||
/**
|
/**
|
||||||
|
* @typedef {import('redux').Action} Action
|
||||||
* @typedef {import('../../../types/index').Choices.Choice} Choice
|
* @typedef {import('../../../types/index').Choices.Choice} Choice
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @argument {Choice} choice
|
* @argument {Choice} choice
|
||||||
* @returns {{ type: string } & Choice}
|
* @returns {Action & Choice}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var choices_addChoice = function addChoice(_ref) {
|
var choices_addChoice = function addChoice(_ref) {
|
||||||
|
@ -3078,7 +3080,7 @@ var choices_addChoice = function addChoice(_ref) {
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @argument {Choice[]} results
|
* @argument {Choice[]} results
|
||||||
* @returns {{ type: string, results: Choice[] }}
|
* @returns {Action & { results: Choice[] }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var choices_filterChoices = function filterChoices(results) {
|
var choices_filterChoices = function filterChoices(results) {
|
||||||
|
@ -3089,7 +3091,7 @@ var choices_filterChoices = function filterChoices(results) {
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @argument {boolean} active
|
* @argument {boolean} active
|
||||||
* @returns {{ type: string, active: boolean }}
|
* @returns {Action & { active: boolean }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var choices_activateChoices = function activateChoices(active) {
|
var choices_activateChoices = function activateChoices(active) {
|
||||||
|
@ -3103,7 +3105,7 @@ var choices_activateChoices = function activateChoices(active) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @returns {{ type: string }}
|
* @returns {Action}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var choices_clearChoices = function clearChoices() {
|
var choices_clearChoices = function clearChoices() {
|
||||||
|
@ -3114,12 +3116,13 @@ var choices_clearChoices = function clearChoices() {
|
||||||
// CONCATENATED MODULE: ./src/scripts/actions/items.js
|
// CONCATENATED MODULE: ./src/scripts/actions/items.js
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @typedef {import('redux').Action} Action
|
||||||
* @typedef {import('../../../types/index').Choices.Item} Item
|
* @typedef {import('../../../types/index').Choices.Item} Item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Item} item
|
* @param {Item} item
|
||||||
* @returns {{ type: string } & Item}
|
* @returns {Action & Item}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var items_addItem = function addItem(_ref) {
|
var items_addItem = function addItem(_ref) {
|
||||||
|
@ -3146,7 +3149,7 @@ var items_addItem = function addItem(_ref) {
|
||||||
/**
|
/**
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
* @param {string} choiceId
|
* @param {string} choiceId
|
||||||
* @returns {{ type: string, id: string, choiceId: string }}
|
* @returns {Action & { id: string, choiceId: string }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var items_removeItem = function removeItem(id, choiceId) {
|
var items_removeItem = function removeItem(id, choiceId) {
|
||||||
|
@ -3159,7 +3162,7 @@ var items_removeItem = function removeItem(id, choiceId) {
|
||||||
/**
|
/**
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
* @param {boolean} highlighted
|
* @param {boolean} highlighted
|
||||||
* @returns {{ type: string, id: string, highlighted: boolean }}
|
* @returns {Action & { id: string, highlighted: boolean }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var items_highlightItem = function highlightItem(id, highlighted) {
|
var items_highlightItem = function highlightItem(id, highlighted) {
|
||||||
|
@ -3172,12 +3175,13 @@ var items_highlightItem = function highlightItem(id, highlighted) {
|
||||||
// CONCATENATED MODULE: ./src/scripts/actions/groups.js
|
// CONCATENATED MODULE: ./src/scripts/actions/groups.js
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @typedef {import('redux').Action} Action
|
||||||
* @typedef {import('../../../types/index').Choices.Group} Group
|
* @typedef {import('../../../types/index').Choices.Group} Group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Group} group
|
* @param {Group} group
|
||||||
* @returns {{ type: string } & Group}
|
* @returns {Action & Group}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var groups_addGroup = function addGroup(_ref) {
|
var groups_addGroup = function addGroup(_ref) {
|
||||||
|
@ -3195,7 +3199,11 @@ var groups_addGroup = function addGroup(_ref) {
|
||||||
};
|
};
|
||||||
// CONCATENATED MODULE: ./src/scripts/actions/misc.js
|
// CONCATENATED MODULE: ./src/scripts/actions/misc.js
|
||||||
/**
|
/**
|
||||||
* @returns {{ type: string }}
|
* @typedef {import('redux').Action} Action
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Action}
|
||||||
*/
|
*/
|
||||||
var clearAll = function clearAll() {
|
var clearAll = function clearAll() {
|
||||||
return {
|
return {
|
||||||
|
@ -3204,7 +3212,7 @@ var clearAll = function clearAll() {
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @param {any} state
|
* @param {any} state
|
||||||
* @returns {{ type: string, state: object }}
|
* @returns {Action & { state: object }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var resetTo = function resetTo(state) {
|
var resetTo = function resetTo(state) {
|
||||||
|
@ -3215,7 +3223,7 @@ var resetTo = function resetTo(state) {
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @param {boolean} isLoading
|
* @param {boolean} isLoading
|
||||||
* @returns {{ type: string, isLoading: boolean }}
|
* @returns {Action & { isLoading: boolean }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var setIsLoading = function setIsLoading(isLoading) {
|
var setIsLoading = function setIsLoading(isLoading) {
|
||||||
|
@ -3297,23 +3305,13 @@ function () {
|
||||||
arrayMerge: function arrayMerge(_, sourceArray) {
|
arrayMerge: function arrayMerge(_, sourceArray) {
|
||||||
return [].concat(sourceArray);
|
return [].concat(sourceArray);
|
||||||
}
|
}
|
||||||
}); // Convert addItemFilter to function
|
});
|
||||||
|
|
||||||
if (userConfig.addItemFilter && typeof userConfig.addItemFilter !== 'function') {
|
|
||||||
var re = userConfig.addItemFilter instanceof RegExp ? userConfig.addItemFilter : new RegExp(userConfig.addItemFilter);
|
|
||||||
this.config.addItemFilter = re.test.bind(re);
|
|
||||||
}
|
|
||||||
|
|
||||||
var invalidConfigOptions = diff(this.config, DEFAULT_CONFIG);
|
var invalidConfigOptions = diff(this.config, DEFAULT_CONFIG);
|
||||||
|
|
||||||
if (invalidConfigOptions.length) {
|
if (invalidConfigOptions.length) {
|
||||||
console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', '));
|
console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', '));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
|
||||||
this.config.renderSelectedChoices = 'auto';
|
|
||||||
}
|
|
||||||
|
|
||||||
var passedElement = typeof element === 'string' ? document.querySelector(element) : element;
|
var passedElement = typeof element === 'string' ? document.querySelector(element) : element;
|
||||||
|
|
||||||
if (!(passedElement instanceof HTMLInputElement || passedElement instanceof HTMLSelectElement)) {
|
if (!(passedElement instanceof HTMLInputElement || passedElement instanceof HTMLSelectElement)) {
|
||||||
|
@ -3324,6 +3322,16 @@ function () {
|
||||||
this._isSelectOneElement = passedElement.type === SELECT_ONE_TYPE;
|
this._isSelectOneElement = passedElement.type === SELECT_ONE_TYPE;
|
||||||
this._isSelectMultipleElement = passedElement.type === SELECT_MULTIPLE_TYPE;
|
this._isSelectMultipleElement = passedElement.type === SELECT_MULTIPLE_TYPE;
|
||||||
this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement;
|
this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement;
|
||||||
|
this.config.searchEnabled = this._isSelectMultipleElement || this.config.searchEnabled;
|
||||||
|
|
||||||
|
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
||||||
|
this.config.renderSelectedChoices = 'auto';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userConfig.addItemFilter && typeof userConfig.addItemFilter !== 'function') {
|
||||||
|
var re = userConfig.addItemFilter instanceof RegExp ? userConfig.addItemFilter : new RegExp(userConfig.addItemFilter);
|
||||||
|
this.config.addItemFilter = re.test.bind(re);
|
||||||
|
}
|
||||||
|
|
||||||
if (this._isTextElement) {
|
if (this._isTextElement) {
|
||||||
this.passedElement = new WrappedInput({
|
this.passedElement = new WrappedInput({
|
||||||
|
@ -3878,13 +3886,13 @@ function () {
|
||||||
|
|
||||||
this.containerOuter.removeLoadingState();
|
this.containerOuter.removeLoadingState();
|
||||||
|
|
||||||
this._setLoading(true);
|
this._startLoading();
|
||||||
|
|
||||||
choicesArrayOrFetcher.forEach(function (groupOrChoice) {
|
choicesArrayOrFetcher.forEach(function (groupOrChoice) {
|
||||||
if (groupOrChoice.choices) {
|
if (groupOrChoice.choices) {
|
||||||
_this11._addGroup({
|
_this11._addGroup({
|
||||||
|
id: parseInt(groupOrChoice.id, 10) || null,
|
||||||
group: groupOrChoice,
|
group: groupOrChoice,
|
||||||
id: groupOrChoice.id || null,
|
|
||||||
valueKey: value,
|
valueKey: value,
|
||||||
labelKey: label
|
labelKey: label
|
||||||
});
|
});
|
||||||
|
@ -3900,7 +3908,7 @@ function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._setLoading(false);
|
this._stopLoading();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -4331,8 +4339,12 @@ function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_proto._setLoading = function _setLoading(isLoading) {
|
_proto._startLoading = function _startLoading() {
|
||||||
this._store.dispatch(setIsLoading(isLoading));
|
this._store.dispatch(setIsLoading(true));
|
||||||
|
};
|
||||||
|
|
||||||
|
_proto._stopLoading = function _stopLoading() {
|
||||||
|
this._store.dispatch(setIsLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
_proto._handleLoadingState = function _handleLoadingState(setLoading) {
|
_proto._handleLoadingState = function _handleLoadingState(setLoading) {
|
||||||
|
@ -4505,39 +4517,21 @@ function () {
|
||||||
documentElement.removeEventListener('keydown', this._onKeyDown, true);
|
documentElement.removeEventListener('keydown', this._onKeyDown, true);
|
||||||
documentElement.removeEventListener('touchend', this._onTouchEnd, true);
|
documentElement.removeEventListener('touchend', this._onTouchEnd, true);
|
||||||
documentElement.removeEventListener('mousedown', this._onMouseDown, true);
|
documentElement.removeEventListener('mousedown', this._onMouseDown, true);
|
||||||
documentElement.removeEventListener('keyup', this._onKeyUp, {
|
documentElement.removeEventListener('keyup', this._onKeyUp);
|
||||||
passive: true
|
documentElement.removeEventListener('click', this._onClick);
|
||||||
});
|
documentElement.removeEventListener('touchmove', this._onTouchMove);
|
||||||
documentElement.removeEventListener('click', this._onClick, {
|
documentElement.removeEventListener('mouseover', this._onMouseOver);
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
documentElement.removeEventListener('touchmove', this._onTouchMove, {
|
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
documentElement.removeEventListener('mouseover', this._onMouseOver, {
|
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this._isSelectOneElement) {
|
if (this._isSelectOneElement) {
|
||||||
this.containerOuter.element.removeEventListener('focus', this._onFocus, {
|
this.containerOuter.element.removeEventListener('focus', this._onFocus);
|
||||||
passive: true
|
this.containerOuter.element.removeEventListener('blur', this._onBlur);
|
||||||
});
|
|
||||||
this.containerOuter.element.removeEventListener('blur', this._onBlur, {
|
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input.element.removeEventListener('focus', this._onFocus, {
|
this.input.element.removeEventListener('focus', this._onFocus);
|
||||||
passive: true
|
this.input.element.removeEventListener('blur', this._onBlur);
|
||||||
});
|
|
||||||
this.input.element.removeEventListener('blur', this._onBlur, {
|
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.input.element.form) {
|
if (this.input.element.form) {
|
||||||
this.input.element.form.removeEventListener('reset', this._onFormReset, {
|
this.input.element.form.removeEventListener('reset', this._onFormReset);
|
||||||
passive: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input.removeEventListeners();
|
this.input.removeEventListeners();
|
||||||
|
@ -5027,7 +5021,7 @@ function () {
|
||||||
var passedCustomProperties = customProperties;
|
var passedCustomProperties = customProperties;
|
||||||
var items = this._store.items;
|
var items = this._store.items;
|
||||||
var passedLabel = label || passedValue;
|
var passedLabel = label || passedValue;
|
||||||
var passedOptionId = parseInt(choiceId, 10) || -1;
|
var passedOptionId = choiceId || -1;
|
||||||
var group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
|
var group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
|
||||||
var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it
|
var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it
|
||||||
|
|
||||||
|
@ -5127,12 +5121,12 @@ function () {
|
||||||
var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId;
|
var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId;
|
||||||
|
|
||||||
this._store.dispatch(choices_addChoice({
|
this._store.dispatch(choices_addChoice({
|
||||||
value: value,
|
|
||||||
label: choiceLabel,
|
|
||||||
id: choiceId,
|
id: choiceId,
|
||||||
groupId: groupId,
|
groupId: groupId,
|
||||||
disabled: isDisabled,
|
|
||||||
elementId: choiceElementId,
|
elementId: choiceElementId,
|
||||||
|
value: value,
|
||||||
|
label: choiceLabel,
|
||||||
|
disabled: isDisabled,
|
||||||
customProperties: customProperties,
|
customProperties: customProperties,
|
||||||
placeholder: placeholder,
|
placeholder: placeholder,
|
||||||
keyCode: keyCode
|
keyCode: keyCode
|
||||||
|
@ -5288,7 +5282,7 @@ function () {
|
||||||
this._highlightPosition = 0;
|
this._highlightPosition = 0;
|
||||||
this._isSearching = false;
|
this._isSearching = false;
|
||||||
|
|
||||||
this._setLoading(true);
|
this._startLoading();
|
||||||
|
|
||||||
if (this._presetGroups.length) {
|
if (this._presetGroups.length) {
|
||||||
this._addPredefinedGroups(this._presetGroups);
|
this._addPredefinedGroups(this._presetGroups);
|
||||||
|
@ -5296,7 +5290,7 @@ function () {
|
||||||
this._addPredefinedChoices(this._presetChoices);
|
this._addPredefinedChoices(this._presetChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setLoading(false);
|
this._stopLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._isTextElement) {
|
if (this._isTextElement) {
|
||||||
|
@ -5334,13 +5328,14 @@ function () {
|
||||||
// If sorting is enabled or the user is searching, filter choices
|
// If sorting is enabled or the user is searching, filter choices
|
||||||
if (this.config.shouldSort) {
|
if (this.config.shouldSort) {
|
||||||
choices.sort(this.config.sorter);
|
choices.sort(this.config.sorter);
|
||||||
} // Determine whether there is a selected choice
|
}
|
||||||
|
|
||||||
|
|
||||||
var hasSelectedChoice = choices.some(function (choice) {
|
var hasSelectedChoice = choices.some(function (choice) {
|
||||||
return choice.selected;
|
return choice.selected;
|
||||||
}); // Add each choice
|
});
|
||||||
|
var firstEnabledChoiceIndex = choices.findIndex(function (choice) {
|
||||||
|
return choice.disabled === undefined || !choice.disabled;
|
||||||
|
});
|
||||||
choices.forEach(function (choice, index) {
|
choices.forEach(function (choice, index) {
|
||||||
var value = choice.value,
|
var value = choice.value,
|
||||||
label = choice.label,
|
label = choice.label,
|
||||||
|
@ -5355,12 +5350,15 @@ function () {
|
||||||
id: choice.id || null
|
id: choice.id || null
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If there is a selected choice already or the choice is not
|
/**
|
||||||
// the first in the array, add each choice normally
|
* If there is a selected choice already or the choice is not the first in
|
||||||
// Otherwise pre-select the first choice in the array if it's a single select
|
* the array, add each choice normally.
|
||||||
var shouldPreselect = _this22._isSelectOneElement && !hasSelectedChoice && index === 0;
|
*
|
||||||
|
* Otherwise we pre-select the first enabled choice in the array ("select-one" only)
|
||||||
|
*/
|
||||||
|
var shouldPreselect = _this22._isSelectOneElement && !hasSelectedChoice && index === firstEnabledChoiceIndex;
|
||||||
var isSelected = shouldPreselect ? true : choice.selected;
|
var isSelected = shouldPreselect ? true : choice.selected;
|
||||||
var isDisabled = shouldPreselect ? false : choice.disabled;
|
var isDisabled = choice.disabled;
|
||||||
|
|
||||||
_this22._addChoice({
|
_this22._addChoice({
|
||||||
value: value,
|
value: value,
|
||||||
|
|
2
public/assets/scripts/choices.min.js
vendored
2
public/assets/scripts/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -102,6 +102,18 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div data-test-hook="disabled-first-choice-via-options">
|
||||||
|
<label for="choices-disabled-choice-via-options"
|
||||||
|
>Disabled first choice by options</label
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
class="form-control"
|
||||||
|
name="choices-disabled-choice-via-options"
|
||||||
|
id="choices-disabled-choice-via-options"
|
||||||
|
>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div data-test-hook="add-items-disabled">
|
<div data-test-hook="add-items-disabled">
|
||||||
<label for="choices-add-items-disabled">Add items disabled</label>
|
<label for="choices-add-items-disabled">Add items disabled</label>
|
||||||
<select
|
<select
|
||||||
|
@ -373,6 +385,29 @@
|
||||||
removeItemButton: true,
|
removeItemButton: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Choices('#choices-disabled-choice-via-options', {
|
||||||
|
removeItemButton: true,
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
value: 'Choice 1',
|
||||||
|
label: 'Choice 1',
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Choice 2',
|
||||||
|
label: 'Choice 2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Choice 3',
|
||||||
|
label: 'Choice 3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'Choice 4',
|
||||||
|
label: 'Choice 4',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
new Choices('#choices-add-items-disabled', {
|
new Choices('#choices-add-items-disabled', {
|
||||||
addItems: false,
|
addItems: false,
|
||||||
});
|
});
|
||||||
|
|
|
@ -614,13 +614,13 @@ class Choices {
|
||||||
|
|
||||||
this.containerOuter.removeLoadingState();
|
this.containerOuter.removeLoadingState();
|
||||||
|
|
||||||
this._setLoading(true);
|
this._startLoading();
|
||||||
|
|
||||||
choicesArrayOrFetcher.forEach(groupOrChoice => {
|
choicesArrayOrFetcher.forEach(groupOrChoice => {
|
||||||
if (groupOrChoice.choices) {
|
if (groupOrChoice.choices) {
|
||||||
this._addGroup({
|
this._addGroup({
|
||||||
|
id: parseInt(groupOrChoice.id, 10) || null,
|
||||||
group: groupOrChoice,
|
group: groupOrChoice,
|
||||||
id: groupOrChoice.id || null,
|
|
||||||
valueKey: value,
|
valueKey: value,
|
||||||
labelKey: label,
|
labelKey: label,
|
||||||
});
|
});
|
||||||
|
@ -636,7 +636,7 @@ class Choices {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._setLoading(false);
|
this._stopLoading();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1076,8 +1076,12 @@ class Choices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_setLoading(isLoading) {
|
_startLoading() {
|
||||||
this._store.dispatch(setIsLoading(isLoading));
|
this._store.dispatch(setIsLoading(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
_stopLoading() {
|
||||||
|
this._store.dispatch(setIsLoading(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleLoadingState(setLoading = true) {
|
_handleLoadingState(setLoading = true) {
|
||||||
|
@ -1810,7 +1814,7 @@ class Choices {
|
||||||
const passedCustomProperties = customProperties;
|
const passedCustomProperties = customProperties;
|
||||||
const { items } = this._store;
|
const { items } = this._store;
|
||||||
const passedLabel = label || passedValue;
|
const passedLabel = label || passedValue;
|
||||||
const passedOptionId = parseInt(choiceId, 10) || -1;
|
const passedOptionId = choiceId || -1;
|
||||||
const group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
|
const group = groupId >= 0 ? this._store.getGroupById(groupId) : null;
|
||||||
const id = items ? items.length + 1 : 1;
|
const id = items ? items.length + 1 : 1;
|
||||||
|
|
||||||
|
@ -1904,12 +1908,12 @@ class Choices {
|
||||||
|
|
||||||
this._store.dispatch(
|
this._store.dispatch(
|
||||||
addChoice({
|
addChoice({
|
||||||
value,
|
|
||||||
label: choiceLabel,
|
|
||||||
id: choiceId,
|
id: choiceId,
|
||||||
groupId,
|
groupId,
|
||||||
disabled: isDisabled,
|
|
||||||
elementId: choiceElementId,
|
elementId: choiceElementId,
|
||||||
|
value,
|
||||||
|
label: choiceLabel,
|
||||||
|
disabled: isDisabled,
|
||||||
customProperties,
|
customProperties,
|
||||||
placeholder,
|
placeholder,
|
||||||
keyCode,
|
keyCode,
|
||||||
|
@ -2076,7 +2080,7 @@ class Choices {
|
||||||
if (this._isSelectElement) {
|
if (this._isSelectElement) {
|
||||||
this._highlightPosition = 0;
|
this._highlightPosition = 0;
|
||||||
this._isSearching = false;
|
this._isSearching = false;
|
||||||
this._setLoading(true);
|
this._startLoading();
|
||||||
|
|
||||||
if (this._presetGroups.length) {
|
if (this._presetGroups.length) {
|
||||||
this._addPredefinedGroups(this._presetGroups);
|
this._addPredefinedGroups(this._presetGroups);
|
||||||
|
@ -2084,7 +2088,7 @@ class Choices {
|
||||||
this._addPredefinedChoices(this._presetChoices);
|
this._addPredefinedChoices(this._presetChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setLoading(false);
|
this._stopLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._isTextElement) {
|
if (this._isTextElement) {
|
||||||
|
@ -2122,10 +2126,11 @@ class Choices {
|
||||||
choices.sort(this.config.sorter);
|
choices.sort(this.config.sorter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether there is a selected choice
|
|
||||||
const hasSelectedChoice = choices.some(choice => choice.selected);
|
const hasSelectedChoice = choices.some(choice => choice.selected);
|
||||||
|
const firstEnabledChoiceIndex = choices.findIndex(
|
||||||
|
choice => choice.disabled === undefined || !choice.disabled,
|
||||||
|
);
|
||||||
|
|
||||||
// Add each choice
|
|
||||||
choices.forEach((choice, index) => {
|
choices.forEach((choice, index) => {
|
||||||
const { value, label, customProperties, placeholder } = choice;
|
const { value, label, customProperties, placeholder } = choice;
|
||||||
|
|
||||||
|
@ -2137,13 +2142,19 @@ class Choices {
|
||||||
id: choice.id || null,
|
id: choice.id || null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If there is a selected choice already or the choice is not
|
/**
|
||||||
// the first in the array, add each choice normally
|
* If there is a selected choice already or the choice is not the first in
|
||||||
// Otherwise pre-select the first choice in the array if it's a single select
|
* the array, add each choice normally.
|
||||||
|
*
|
||||||
|
* Otherwise we pre-select the first enabled choice in the array ("select-one" only)
|
||||||
|
*/
|
||||||
const shouldPreselect =
|
const shouldPreselect =
|
||||||
this._isSelectOneElement && !hasSelectedChoice && index === 0;
|
this._isSelectOneElement &&
|
||||||
|
!hasSelectedChoice &&
|
||||||
|
index === firstEnabledChoiceIndex;
|
||||||
|
|
||||||
const isSelected = shouldPreselect ? true : choice.selected;
|
const isSelected = shouldPreselect ? true : choice.selected;
|
||||||
const isDisabled = shouldPreselect ? false : choice.disabled;
|
const isDisabled = choice.disabled;
|
||||||
|
|
||||||
this._addChoice({
|
this._addChoice({
|
||||||
value,
|
value,
|
||||||
|
|
|
@ -1539,12 +1539,12 @@ describe('choices', () => {
|
||||||
const label = 'label';
|
const label = 'label';
|
||||||
const choices = [
|
const choices = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: 1,
|
||||||
value: '1',
|
value: '1',
|
||||||
label: 'Test 1',
|
label: 'Test 1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: 2,
|
||||||
value: '2',
|
value: '2',
|
||||||
label: 'Test 2',
|
label: 'Test 2',
|
||||||
},
|
},
|
||||||
|
|
|
@ -44,7 +44,7 @@ export default class List {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} element
|
* @param {Element} element
|
||||||
* @param {1 | -1} direction
|
* @param {1 | -1} direction
|
||||||
*/
|
*/
|
||||||
scrollToChildElement(element, direction) {
|
scrollToChildElement(element, direction) {
|
||||||
|
|
|
@ -83,8 +83,8 @@ export const getAdjacentEl = (startEl, selector, direction = 1) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} element
|
* @param {Element} element
|
||||||
* @param {HTMLElement} parent
|
* @param {Element} parent
|
||||||
* @param {-1 | 1} direction
|
* @param {-1 | 1} direction
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
@ -125,7 +125,7 @@ export const sanitise = value => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {function}
|
* @returns {() => (str: string) => Element}
|
||||||
*/
|
*/
|
||||||
export const strToEl = (() => {
|
export const strToEl = (() => {
|
||||||
const tmpEl = document.createElement('div');
|
const tmpEl = document.createElement('div');
|
||||||
|
|
|
@ -152,10 +152,10 @@ export default class Store {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get group by group id
|
* Get group by group id
|
||||||
* @param {string} id Group ID
|
* @param {number} id Group ID
|
||||||
* @returns {Group | undefined} Group data
|
* @returns {Group | undefined} Group data
|
||||||
*/
|
*/
|
||||||
getGroupById(id) {
|
getGroupById(id) {
|
||||||
return this.groups.find(group => group.id === parseInt(id, 10));
|
return this.groups.find(group => group.id === id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,10 +245,8 @@ describe('reducers/store', () => {
|
||||||
|
|
||||||
describe('getGroupById', () => {
|
describe('getGroupById', () => {
|
||||||
it('returns group by id', () => {
|
it('returns group by id', () => {
|
||||||
const id = '1';
|
const id = 1;
|
||||||
const expectedResponse = state.groups.find(
|
const expectedResponse = state.groups.find(group => group.id === id);
|
||||||
group => group.id === parseInt(id, 10),
|
|
||||||
);
|
|
||||||
const actualResponse = instance.getGroupById(id);
|
const actualResponse = instance.getGroupById(id);
|
||||||
expect(actualResponse).to.eql(expectedResponse);
|
expect(actualResponse).to.eql(expectedResponse);
|
||||||
});
|
});
|
||||||
|
|
16
types/index.d.ts
vendored
16
types/index.d.ts
vendored
|
@ -23,12 +23,12 @@ declare namespace Choices {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Choice {
|
interface Choice {
|
||||||
id?: string;
|
id?: number;
|
||||||
customProperties?: Record<string, any>;
|
customProperties?: Record<string, any>;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
elementId?: string;
|
elementId?: string;
|
||||||
groupId?: string;
|
groupId?: number;
|
||||||
keyCode?: number;
|
keyCode?: number;
|
||||||
label: string;
|
label: string;
|
||||||
placeholder?: boolean;
|
placeholder?: boolean;
|
||||||
|
@ -37,14 +37,14 @@ declare namespace Choices {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Group {
|
interface Group {
|
||||||
id?: string;
|
id?: number;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
value: any;
|
value: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Item extends Choice {
|
interface Item extends Choice {
|
||||||
choiceId?: string;
|
choiceId?: number;
|
||||||
keyCode?: number;
|
keyCode?: number;
|
||||||
highlighted?: boolean;
|
highlighted?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ declare namespace Choices {
|
||||||
* Arguments: id, value, label, groupValue, keyCode
|
* Arguments: id, value, label, groupValue, keyCode
|
||||||
*/
|
*/
|
||||||
addItem: CustomEvent<{
|
addItem: CustomEvent<{
|
||||||
id: string;
|
id: number;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
groupValue: string;
|
groupValue: string;
|
||||||
|
@ -76,7 +76,7 @@ declare namespace Choices {
|
||||||
* Arguments: id, value, label, groupValue
|
* Arguments: id, value, label, groupValue
|
||||||
*/
|
*/
|
||||||
removeItem: CustomEvent<{
|
removeItem: CustomEvent<{
|
||||||
id: string;
|
id: number;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
groupValue: string;
|
groupValue: string;
|
||||||
|
@ -90,7 +90,7 @@ declare namespace Choices {
|
||||||
* Arguments: id, value, label, groupValue
|
* Arguments: id, value, label, groupValue
|
||||||
*/
|
*/
|
||||||
highlightItem: CustomEvent<{
|
highlightItem: CustomEvent<{
|
||||||
id: string;
|
id: number;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
groupValue: string;
|
groupValue: string;
|
||||||
|
@ -104,7 +104,7 @@ declare namespace Choices {
|
||||||
* Arguments: id, value, label, groupValue
|
* Arguments: id, value, label, groupValue
|
||||||
*/
|
*/
|
||||||
unhighlightItem: CustomEvent<{
|
unhighlightItem: CustomEvent<{
|
||||||
id: string;
|
id: number;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
groupValue: string;
|
groupValue: string;
|
||||||
|
|
Loading…
Reference in a new issue