Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
fix(Picky): Select all is checked when no options
Browse files Browse the repository at this point in the history
fix #115
  • Loading branch information
Aidurber committed Apr 6, 2019
1 parent fb3f1d8 commit dcc95b6
Show file tree
Hide file tree
Showing 5 changed files with 1,380 additions and 905 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"prettier": "prettier --write {src,tests}{/**/,/}*.js",
"dev": "rollup -c -w",
"dev:production": "cross-env NODE_ENV=production rollup -c -w",
"pretest": "npm run build",
"lint": "eslint src/**/*.js",
"test": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watchAll",
Expand All @@ -19,15 +18,15 @@
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-jest": "^24.7.1",
"babel-plugin-react-remove-properties": "^0.3.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.19",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"enzyme": "^3.7.0",
Expand All @@ -38,11 +37,11 @@
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.12.3",
"husky": "^1.1.2",
"jest": "^23.6.0",
"jest": "^24.7.1",
"prettier": "^1.14.3",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-testing-library": "^5.7.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-testing-library": "^5.9.0",
"rollup": "^1.0.0",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.2.0",
Expand Down Expand Up @@ -71,14 +70,10 @@
"!tests/**"
],
"transform": {
"^.+\\.jsx$": "babel-jest",
"^.+\\.js$": "babel-jest",
"^.+\\.jsx?$": "babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
]
}
},
"peerDependencies": {
"prop-types": "> 15.6.0",
Expand Down
4 changes: 4 additions & 0 deletions src/Picky.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Picky extends React.PureComponent {
const { value, valueKey, options } = this.props;
const selectedValue = overrideSelected || value;

// If there are no options we are getting a false positive for all items being selected
if (options && options.length === 0) {
return false;
}
let copiedOptions = options.map(this.getValue);
let copiedValues = Array.isArray(selectedValue)
? selectedValue.map(this.getValue)
Expand Down
18 changes: 17 additions & 1 deletion tests/Picky.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ describe('Picky', () => {

it('should be disabled when disabled prop supplied', () => {
const options = [1, 2];
const { getByTestId, rerender, debug } = rtlRender(
const { getByTestId, rerender } = rtlRender(
<Picky
options={options}
includeSelectAll
Expand All @@ -994,4 +994,20 @@ describe('Picky', () => {

expect(selectAllCheckbox.checked).toEqual(false);
});

it('should not have select all checked when there are no options', () => {
const options = [];
const { getByTestId, debug } = rtlRender(
<Picky
options={options}
includeSelectAll
open={true}
multiple
disabled
value={[]}
/>
);
const selectAllCheckbox = getByTestId('selectall-checkbox');
expect(selectAllCheckbox.checked).toEqual(false);
});
});
Loading

0 comments on commit dcc95b6

Please sign in to comment.