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

Commit

Permalink
feat(Picky): keepOpen logic
Browse files Browse the repository at this point in the history
Auto close single select if keepOpen is false. Stays open if true.

closes #23
  • Loading branch information
Aidurber committed Dec 30, 2017
1 parent 7b77afe commit a01b7d9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Picky.defaultProps = {
dropdownHeight: 300,
onChange: () => {},
itemHeight: 35,
tabIndex: 0
tabIndex: 0,
keepOpen: true
};
Picky.propTypes = {
placeholder: PropTypes.string,
Expand All @@ -108,7 +109,8 @@ Picky.propTypes = {
labelKey: PropTypes.string,
render: PropTypes.func,
itemHeight: PropTypes.number,
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
keepOpen: PropTypes.bool
};
```

Expand All @@ -133,6 +135,7 @@ Picky.propTypes = {
* `render` - Used for custom rendering of items in the dropdown. More info below.
* `itemHeight` - Used when dropdown item height is larger than 35px. This is so the virtualised list can calculate correctly.
* `tabIndex` - Pass tabIndex to component for accessibility. Defaults to 0
* `keepOpen` - Default true. Single selects close automatically when selecting a value unless this is set to true.

## Custom rendering

Expand Down Expand Up @@ -169,8 +172,7 @@ You can render out custom items for the dropdown.
key={item[valueKey]} // required
onClick={() => selectValue(item)}
>
{' '}
// required to select item
{/* required to select item */}
<input type="checkbox" checked={isSelected} readOnly />
<span style={{ fontSize: '30px' }}>{item[labelKey]}</span>
</li>
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3198,7 +3198,8 @@ var Picky$1 = function (_React$Component) {
}, {
key: 'handleOutsideClick',
value: function handleOutsideClick(e) {
if (this.node && this.node.contains(e.target)) {
var keepOpen = this.props.keepOpen || this.props.multiple;
if (this.node && this.node.contains(e.target) && keepOpen) {
return;
}
this.toggleDropDown();
Expand Down Expand Up @@ -3324,7 +3325,8 @@ Picky$1.defaultProps = {
dropdownHeight: 300,
onChange: function onChange() {},
itemHeight: 35,
tabIndex: 0
tabIndex: 0,
keepOpen: true
};
Picky$1.propTypes = {
placeholder: PropTypes__default.string,
Expand All @@ -3345,7 +3347,8 @@ Picky$1.propTypes = {
labelKey: PropTypes__default.string,
render: PropTypes__default.func,
itemHeight: PropTypes__default.number,
tabIndex: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number])
tabIndex: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
keepOpen: PropTypes__default.bool
};

module.exports = Picky$1;
10 changes: 6 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Picky.defaultProps = {
dropdownHeight: 300,
onChange: () => {},
itemHeight: 35,
tabIndex: 0
tabIndex: 0,
keepOpen: true
};
Picky.propTypes = {
placeholder: PropTypes.string,
Expand All @@ -108,7 +109,8 @@ Picky.propTypes = {
labelKey: PropTypes.string,
render: PropTypes.func,
itemHeight: PropTypes.number,
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
keepOpen: PropTypes.bool
};
```

Expand All @@ -133,6 +135,7 @@ Picky.propTypes = {
* `render` - Used for custom rendering of items in the dropdown. More info below.
* `itemHeight` - Used when dropdown item height is larger than 35px. This is so the virtualised list can calculate correctly.
* `tabIndex` - Pass tabIndex to component for accessibility. Defaults to 0
* `keepOpen` - Default true. Single selects close automatically when selecting a value unless this is set to true.

## Custom rendering

Expand Down Expand Up @@ -169,8 +172,7 @@ You can render out custom items for the dropdown.
key={item[valueKey]} // required
onClick={() => selectValue(item)}
>
{' '}
// required to select item
{/* required to select item */}
<input type="checkbox" checked={isSelected} readOnly />
<span style={{ fontSize: '30px' }}>{item[labelKey]}</span>
</li>
Expand Down
9 changes: 6 additions & 3 deletions src/Picky.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class Picky extends React.Component {
}

handleOutsideClick(e) {
if (this.node && this.node.contains(e.target)) {
const keepOpen = this.props.keepOpen || this.props.multiple;
if (this.node && this.node.contains(e.target) && keepOpen) {
return;
}
this.toggleDropDown();
Expand Down Expand Up @@ -336,7 +337,8 @@ Picky.defaultProps = {
dropdownHeight: 300,
onChange: () => {},
itemHeight: 35,
tabIndex: 0
tabIndex: 0,
keepOpen: true
};
Picky.propTypes = {
placeholder: PropTypes.string,
Expand All @@ -362,7 +364,8 @@ Picky.propTypes = {
labelKey: PropTypes.string,
render: PropTypes.func,
itemHeight: PropTypes.number,
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
keepOpen: PropTypes.bool
};

export default Picky;

0 comments on commit a01b7d9

Please sign in to comment.