mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-21 06:56:34 +02:00
Close dropdown on enter for single select boxes
This commit is contained in:
parent
c4ed167a02
commit
fc64449874
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,6 @@ import Store from './store/index.js';
|
||||||
* To do:
|
* To do:
|
||||||
* - Remove item by clicking a target
|
* - Remove item by clicking a target
|
||||||
* - Set input width based on the size of the contents
|
* - Set input width based on the size of the contents
|
||||||
* - Single select input support
|
|
||||||
* - Populate options by function
|
* - Populate options by function
|
||||||
*/
|
*/
|
||||||
export class Choices {
|
export class Choices {
|
||||||
|
@ -759,9 +758,9 @@ export class Choices {
|
||||||
|
|
||||||
// Whether or not the dropdown should appear above or below input
|
// Whether or not the dropdown should appear above or below input
|
||||||
if(shouldFlip) {
|
if(shouldFlip) {
|
||||||
this.dropdown.classList.add(this.options.classNames.flippedState);
|
this.containerOuter.classList.add(this.options.classNames.flippedState);
|
||||||
} else {
|
} else {
|
||||||
this.dropdown.classList.remove(this.options.classNames.flippedState);
|
this.containerOuter.classList.remove(this.options.classNames.flippedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,13 +770,13 @@ export class Choices {
|
||||||
*/
|
*/
|
||||||
hideDropdown() {
|
hideDropdown() {
|
||||||
// A dropdown flips if it does not have space below the input
|
// A dropdown flips if it does not have space below the input
|
||||||
const isFlipped = this.dropdown.classList.contains(this.options.classNames.flippedState);
|
const isFlipped = this.containerOuter.classList.contains(this.options.classNames.flippedState);
|
||||||
|
|
||||||
this.containerOuter.classList.remove(this.options.classNames.openState);
|
this.containerOuter.classList.remove(this.options.classNames.openState);
|
||||||
this.dropdown.classList.remove(this.options.classNames.activeState);
|
this.dropdown.classList.remove(this.options.classNames.activeState);
|
||||||
|
|
||||||
if(isFlipped) {
|
if(isFlipped) {
|
||||||
this.dropdown.classList.remove(this.options.classNames.flippedState);
|
this.containerOuter.classList.remove(this.options.classNames.flippedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,17 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
border: 1px solid #DDDDDD;
|
border: 1px solid #DDDDDD;
|
||||||
border-radius: .25rem;
|
border-radius: .25rem;
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
cursor: text; }
|
cursor: text;
|
||||||
.is-focused .choices__inner {
|
overflow: hidden; }
|
||||||
border-color: #b7b7b7; }
|
|
||||||
.choices__inner:focus {
|
.choices__inner:focus {
|
||||||
outline: 1px solid #00BCD4;
|
outline: 1px solid #00BCD4;
|
||||||
outline-offset: -1px; }
|
outline-offset: -1px; }
|
||||||
|
.is-focused .choices__inner {
|
||||||
|
border-color: #b7b7b7; }
|
||||||
|
.is-open .choices__inner {
|
||||||
|
border-radius: .25rem .25rem 0 0; }
|
||||||
|
.is-flipped.is-open .choices__inner {
|
||||||
|
border-radius: 0 0 .25rem .25rem; }
|
||||||
|
|
||||||
.choices__list {
|
.choices__list {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@ -93,8 +98,6 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
will-change: scroll-position; }
|
will-change: scroll-position; }
|
||||||
.is-open .choices__list--dropdown {
|
|
||||||
border-color: #b7b7b7; }
|
|
||||||
.choices__list--dropdown .choices__item {
|
.choices__list--dropdown .choices__item {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
font-size: 1.4rem; }
|
font-size: 1.4rem; }
|
||||||
|
@ -111,17 +114,16 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
background-color: #f2f2f2; }
|
background-color: #f2f2f2; }
|
||||||
.choices__list--dropdown .choices__item--selectable.is-highlighted:after {
|
.choices__list--dropdown .choices__item--selectable.is-highlighted:after {
|
||||||
opacity: .5; }
|
opacity: .5; }
|
||||||
|
.is-open .choices__list--dropdown {
|
||||||
|
border-color: #b7b7b7; }
|
||||||
.choices__list--dropdown.is-active {
|
.choices__list--dropdown.is-active {
|
||||||
display: block; }
|
display: block; }
|
||||||
.choices__list--dropdown.is-flipped {
|
.is-flipped .choices__list--dropdown {
|
||||||
top: auto;
|
top: auto;
|
||||||
bottom: 100%;
|
bottom: 100%;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: -1px;
|
margin-bottom: -1px;
|
||||||
border-bottom-left-radius: 0;
|
border-radius: .25rem .25rem 0 0; }
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
border-top-left-radius: .25rem;
|
|
||||||
border-top-right-radius: .25rem; }
|
|
||||||
|
|
||||||
.choices__item {
|
.choices__item {
|
||||||
cursor: default; }
|
cursor: default; }
|
||||||
|
|
2
assets/styles/css/choices.min.css
vendored
2
assets/styles/css/choices.min.css
vendored
|
@ -1 +1 @@
|
||||||
*,:after,:before{box-sizing:border-box}body,html{margin:0;height:100%;widows:100%}html{font-size:62.5%}body{background-color:#333;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;color:#fff}label{display:block;margin-bottom:.8rem;font-size:1.4rem;font-weight:500}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:500}.container{display:block;margin:auto;max-width:35em;padding:2.4rem}.section{background-color:#fff;padding:2.4rem;color:#333}.choices{margin-bottom:2.4rem;position:relative}.choices__inner{background-color:#f9f9f9;padding:.75rem .75rem .375rem;border:1px solid #ddd;border-radius:.25rem;font-size:1.4rem;cursor:text}.is-focused .choices__inner{border-color:#b7b7b7}.choices__inner:focus{outline:1px solid #00bcd4;outline-offset:-1px}.choices__list{margin:0;padding-left:0;list-style-type:none}.choices__list--single{display:inline-block;padding:.4rem}.choices__list--multiple{display:inline}.choices__list--multiple .choices__item{display:inline-block;border-radius:2rem;padding:.4rem 1rem;font-size:1.2rem;margin-right:.375rem;margin-bottom:.375rem;background-color:#00bcd4;border:1px solid #00b1c7;color:#fff;word-break:break-all}.choices__list--multiple .choices__item.is-selected{background-color:#00a5bb}.choices__list--dropdown{display:none;z-index:1;position:absolute;width:100%;background-color:#fff;border:1px solid #ddd;top:100%;margin-top:-1px;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem;max-height:300px;overflow:auto;will-change:scroll-position}.is-open .choices__list--dropdown{border-color:#b7b7b7}.choices__list--dropdown .choices__item{padding:1rem;font-size:1.4rem}.choices__list--dropdown .choices__item--selectable.is-highlighted:after,.choices__list--dropdown .choices__item.is-selected{opacity:.5}.choices__list--dropdown .choices__item.is-selected:hover{background-color:#fff}.choices__list--dropdown .choices__item--selectable:after{content:"Press to select";font-size:12px;opacity:0;float:right}.choices__list--dropdown .choices__item--selectable.is-highlighted{background-color:#f2f2f2}.choices__list--dropdown.is-active{display:block}.choices__list--dropdown.is-flipped{top:auto;bottom:100%;margin-top:0;margin-bottom:-1px;border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:.25rem;border-top-right-radius:.25rem}.choices__item{cursor:default}.choices__item--selectable{cursor:pointer}.choices__item--disabled{cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:.5}.choices__group .choices__heading{font-weight:600;font-size:1.2rem;padding:1rem;border-bottom:1px solid #eaeaea;color:gray}.choices__input{background-color:#f9f9f9;font-size:1.4rem;padding:0;margin-bottom:.5rem;display:inline-block;vertical-align:baseline;border:0;border-radius:0;max-width:100%;padding:.4rem 0 .4rem .2rem}.choices__input:focus{outline:0}
|
*,:after,:before{box-sizing:border-box}body,html{margin:0;height:100%;widows:100%}html{font-size:62.5%}body{background-color:#333;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:1.6rem;color:#fff}label{display:block;margin-bottom:.8rem;font-size:1.4rem;font-weight:500}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:1.2rem;font-weight:500}.container{display:block;margin:auto;max-width:35em;padding:2.4rem}.section{background-color:#fff;padding:2.4rem;color:#333}.choices{margin-bottom:2.4rem;position:relative}.choices__inner{background-color:#f9f9f9;padding:.75rem .75rem .375rem;border:1px solid #ddd;border-radius:.25rem;font-size:1.4rem;cursor:text;overflow:hidden}.choices__inner:focus{outline:1px solid #00bcd4;outline-offset:-1px}.is-focused .choices__inner{border-color:#b7b7b7}.is-open .choices__inner{border-radius:.25rem .25rem 0 0}.is-flipped.is-open .choices__inner{border-radius:0 0 .25rem .25rem}.choices__list{margin:0;padding-left:0;list-style-type:none}.choices__list--single{display:inline-block;padding:.4rem}.choices__list--multiple{display:inline}.choices__list--multiple .choices__item{display:inline-block;border-radius:2rem;padding:.4rem 1rem;font-size:1.2rem;margin-right:.375rem;margin-bottom:.375rem;background-color:#00bcd4;border:1px solid #00b1c7;color:#fff;word-break:break-all}.choices__list--multiple .choices__item.is-selected{background-color:#00a5bb}.choices__list--dropdown{display:none;z-index:1;position:absolute;width:100%;background-color:#fff;border:1px solid #ddd;top:100%;margin-top:-1px;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem;max-height:300px;overflow:auto;will-change:scroll-position}.choices__list--dropdown .choices__item{padding:1rem;font-size:1.4rem}.choices__list--dropdown .choices__item--selectable.is-highlighted:after,.choices__list--dropdown .choices__item.is-selected{opacity:.5}.choices__list--dropdown .choices__item.is-selected:hover{background-color:#fff}.choices__list--dropdown .choices__item--selectable:after{content:"Press to select";font-size:12px;opacity:0;float:right}.choices__list--dropdown .choices__item--selectable.is-highlighted{background-color:#f2f2f2}.is-open .choices__list--dropdown{border-color:#b7b7b7}.choices__list--dropdown.is-active{display:block}.is-flipped .choices__list--dropdown{top:auto;bottom:100%;margin-top:0;margin-bottom:-1px;border-radius:.25rem .25rem 0 0}.choices__item{cursor:default}.choices__item--selectable{cursor:pointer}.choices__item--disabled{cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:.5}.choices__group .choices__heading{font-weight:600;font-size:1.2rem;padding:1rem;border-bottom:1px solid #eaeaea;color:gray}.choices__input{background-color:#f9f9f9;font-size:1.4rem;padding:0;margin-bottom:.5rem;display:inline-block;vertical-align:baseline;border:0;border-radius:0;max-width:100%;padding:.4rem 0 .4rem .2rem}.choices__input:focus{outline:0}
|
|
@ -59,11 +59,15 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
border-radius: .25rem;
|
border-radius: .25rem;
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
cursor: text;
|
cursor: text;
|
||||||
.is-focused & { border-color: darken(#DDDDDD, 15%); }
|
overflow: hidden;
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: 1px solid #00BCD4;
|
outline: 1px solid #00BCD4;
|
||||||
outline-offset: -1px;
|
outline-offset: -1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.is-focused & { border-color: darken(#DDDDDD, 15%); }
|
||||||
|
.is-open & { border-radius: .25rem .25rem 0 0; }
|
||||||
|
.is-flipped.is-open & { border-radius: 0 0 .25rem .25rem; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.choices__list {
|
.choices__list {
|
||||||
|
@ -110,7 +114,6 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
will-change: scroll-position;
|
will-change: scroll-position;
|
||||||
.is-open & { border-color: darken(#DDDDDD, 15%); }
|
|
||||||
.choices__item {
|
.choices__item {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
|
@ -132,16 +135,15 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.is-open & { border-color: darken(#DDDDDD, 15%); }
|
||||||
|
|
||||||
&.is-active { display: block; }
|
&.is-active { display: block; }
|
||||||
&.is-flipped {
|
.is-flipped & {
|
||||||
top: auto;
|
top: auto;
|
||||||
bottom: 100%;
|
bottom: 100%;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: -1px;
|
margin-bottom: -1px;
|
||||||
border-bottom-left-radius: 0;
|
border-radius: .25rem .25rem 0 0;
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
border-top-left-radius: .25rem;
|
|
||||||
border-top-right-radius: .25rem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue