Skip to content

Commit

Permalink
Fix constructor (#693)
Browse files Browse the repository at this point in the history
* breaking test

* Remove ablity to pass multiple elements + tests

* Update readme

* Update README.md

* 🔖 Version 8.0.0

* Remove type definition hack

* Update coverage command

* Add some missing list tests

* Remove .only

* Update demo page to loop over elements

* Update constructor to set initialised flag if already active

* Make templates private

* Throw type error once if element is invalid

* Fix list children bug

* Re-add generic examples to index.html

* Housekeeping

* Use typeof instead of isType where applicable

* Remove isElement

* Add test for isIE11
  • Loading branch information
jshjohnson authored Oct 29, 2019
1 parent 88f63fa commit 0e44a91
Show file tree
Hide file tree
Showing 22 changed files with 842 additions and 544 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
},
"rules": {
"no-restricted-syntax": "off",
"compat/compat": "off"
"compat/compat": "off",
"no-new": "off"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
npm ci
npm run build
npx bundlesize
npm run coverage
npm run test:unit:coverage
npm run test:e2e
env:
CI: true
Expand Down Expand Up @@ -85,4 +85,4 @@ jobs:
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
PUBLISH_DIR: ./public
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
CYPRESS_INSTALL_BINARY: 0
HUSKY_SKIP_INSTALL: true

- run: npm run coverage
- run: npm run test:unit:coverage
env:
FORCE_COLOR: 2

Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ Or include Choices directly:

## Setup

If you pass a selector which targets multiple elements, an array of Choices instances
will be returned. If you target one element, that instance will be returned.
**Note:** If you pass a selector which targets multiple elements, the first matching element will be used. Versions prior to 8.x.x would return multiple Choices instances.

```js
// Pass multiple elements:
const [firstInstance, secondInstance] = new Choices(elements);

// Pass single element:
// Pass single element
const element = document.querySelector('.js-choice');
const choices = new Choices(element);

// Pass reference
Expand All @@ -84,8 +81,8 @@ will be returned. If you target one element, that instance will be returned.
// Pass jQuery element
const choices = new Choices($('.js-choice')[0]);

// Passing options (with default options)
const choices = new Choices(elements, {
// Passing options (with default options)
const choices = new Choices(element, {
silent: false,
items: [],
choices: [],
Expand Down
4 changes: 4 additions & 0 deletions config/jsdom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-param-reassign */

const { JSDOM } = require('jsdom');

const jsdom = new JSDOM(
Expand Down Expand Up @@ -36,6 +38,8 @@ global.HTMLElement = window.HTMLElement;
global.Option = window.Option;
global.HTMLOptionElement = window.HTMLOptionElement;
global.HTMLOptGroupElement = window.HTMLOptGroupElement;
global.HTMLSelectElement = window.HTMLSelectElement;
global.HTMLInputElement = window.HTMLInputElement;
global.DocumentFragment = window.DocumentFragment;
global.requestAnimationFrame = window.requestAnimationFrame;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "choices.js",
"version": "7.1.5",
"version": "8.0.0",
"description": "A vanilla JS customisable text input/select box plugin",
"main": "./public/assets/scripts/choices.js",
"types": "./types/index.d.ts",
"scripts": {
"start": "run-p js:watch css:watch",
"build": "run-p js:build css:build",
"lint": "eslint src/scripts",
"coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha",
"bundlesize": "bundlesize",
"cypress:run": "$(npm bin)/cypress run",
"cypress:open": "$(npm bin)/cypress open",
"cypress:ci": "cypress run --record --group --ci-build-id $GITHUB_SHA",
"test": "run-s test:unit test:e2e",
"test:unit": "NODE_ENV=test mocha",
"test:unit:watch": "NODE_ENV=test mocha --watch --inspect=5556",
"test:unit:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha",
"test:e2e": "run-p --race start cypress:run",
"js:watch": "NODE_ENV=development node server.js",
"js:build": "webpack --config webpack.config.prod.js",
Expand Down
Loading

0 comments on commit 0e44a91

Please sign in to comment.