diff --git a/clean-scripts.config.js b/clean-scripts.config.js index 9bf700e..fe9eebf 100644 --- a/clean-scripts.config.js +++ b/clean-scripts.config.js @@ -7,7 +7,7 @@ module.exports = { `file2variable-cli src/angular.template.html -o src/angular-variables.ts --html-minify --base src`, `ngc -p src`, `tsc -p demo`, - `lessc src/select2.less > dist/select2.css`, + `lessc src/select2.less -sm=on > dist/select2.css`, `cleancss -o dist/select2.min.css dist/select2.css`, `cleancss -o demo/index.bundle.css dist/select2.min.css ./node_modules/github-fork-ribbon-css/gh-fork-ribbon.css`, `webpack --display-modules --config demo/webpack.config.js`, diff --git a/src/angular.component.ts b/src/angular.component.ts index 27553a3..95bf56a 100644 --- a/src/angular.component.ts +++ b/src/angular.component.ts @@ -424,10 +424,11 @@ export class Select2 implements ControlValueAccessor { this.option = null; } - const value = this.option ? (this.multiple + const value = this.option + ? (this.multiple ? (this.option as common.Select2Option[]).map(op => op.value) - : (this.option as common.Select2Option).value - ) : undefined; + : (this.option as common.Select2Option).value) + : undefined; if (this._control) { @@ -547,12 +548,12 @@ export class Select2 implements ControlValueAccessor { * found with the designated value, the select trigger is cleared. */ private _setSelectionByValue(value: any | any[]): void { - if ( this.option || value ) { + if (this.option || value) { const isArray = Array.isArray(value); if (this.multiple && value && !isArray) { throw new Error("Non array value."); } else { - const option = common.getOptionByValue(this.data, value); + const option = this.data ? common.getOptionByValue(this.data, value) : null; this.select(option); } diff --git a/src/select2.less b/src/select2.less index e689546..32286f3 100644 --- a/src/select2.less +++ b/src/select2.less @@ -517,7 +517,7 @@ select2.material { } .select2-results__option[aria-selected=true], - .select2-results__option--highlighted[aria-selected] { + .select2-results__option--highlighted[aria-selected] { background-color: rgba(0, 0, 0, 0.04); color: #000; }