Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit 1a17df6

Browse files
committed
fix(oui-select-picker): prevent leaving blank space
If no match value is defined an empty section is created
1 parent 83846cf commit 1a17df6

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

packages/oui-select-picker/src/index.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ describe("ouiSelectPicker", () => {
9898
const radioElement = getRadioInputElement(element);
9999
expect(angular.element(radioElement).attr("value")).toEqual("aValue");
100100
});
101+
102+
it("should allow to pick one of values attribute", () => {
103+
const element = TestUtils.compileTemplate('<oui-select-picker values="[\'aValue\', \'bValue\']"></oui-select-picker>');
104+
105+
const selectElement = element[0].querySelector("oui-select");
106+
expect(angular.element(selectElement)).not.toBeUndefined();
107+
108+
const selectValues = element[0].querySelectorAll(".oui-dropdown-option");
109+
expect(angular.element(selectValues[0]).text().trim()).toEqual("aValue");
110+
});
111+
112+
it("should display radio value according to match", () => {
113+
const element = TestUtils.compileTemplate('<oui-select-picker values="[{id: \'a\', name: \'aValue\'}]" match="name"></oui-select-picker>');
114+
115+
const value = element[0].querySelectorAll(".oui-select-picker__value");
116+
expect(angular.element(value).text().trim()).toEqual("aValue");
117+
});
118+
119+
it("should display select values according to match", () => {
120+
const element = TestUtils.compileTemplate('<oui-select-picker values="[{id: \'a\', name: \'aValue\'}, {id: \'b\', name: \'bValue\'}]" match="name"></oui-select-picker>');
121+
122+
const selectValues = element[0].querySelectorAll(".oui-dropdown-option");
123+
expect(angular.element(selectValues[1]).text().trim()).toEqual("bValue");
124+
});
101125
});
102126

103127
describe("disabled attribute", () => {

packages/oui-select-picker/src/select-picker.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@
2828
ng-bind=":: $ctrl.description"
2929
ng-if="$ctrl.description"></span>
3030
<span class="oui-select-picker__value-container oui-select-picker__section"
31-
ng-if="$ctrl.values.length">
31+
ng-if="$ctrl.values.length === 1 && $ctrl.match">
3232
<span class="oui-select-picker__value"
33-
ng-bind=":: $ctrl.getFirstValueMatch($ctrl.match)"
34-
ng-if="$ctrl.values.length === 1"></span>
33+
ng-bind=":: $ctrl.getFirstValueMatch($ctrl.match)">
34+
</span>
35+
</span>
36+
<span class="oui-select-picker__value-container oui-select-picker__section"
37+
ng-if="$ctrl.values.length > 1">
3538
<oui-select name="{{:: $ctrl.name }}"
3639
disabled="$ctrl.disabled"
3740
items="$ctrl.values"
3841
match="{{ $ctrl.match }}"
3942
model="$ctrl.selectedValue"
4043
on-change="$ctrl.onSelectModelChange({ modelValue: $ctrl.selectedValue })"
4144
placeholder="{{:: $ctrl.placeholder || ' - ' }}"
42-
data-align="end"
43-
ng-if="$ctrl.values.length > 1">
44-
<span ng-bind=":: $ctrl.$scope.$parent.getItemValue($item, $ctrl.match)"></span>
45+
data-align="end">
46+
<span ng-if="$ctrl.match" ng-bind=":: $ctrl.$scope.$parent.getItemValue($item, $ctrl.match)"></span>
47+
<span ng-if="!$ctrl.match" ng-bind=":: $item"></span>
4548
</oui-select>
4649
</span>
4750
<span class="oui-select-picker__transclude-container"

0 commit comments

Comments
 (0)