) {
this.dropdownShow = event.detail;
+ this.hasFocus = event.detail;
if (event.detail) {
this.inputRef.focus();
this.inputRef.select();
- this.navigationItem = this.items[0];
- this.setHoverEffectForNavigatedSelectItem();
this.removeHiddenFromItems();
+ this.isDropdownEmpty = this.isEveryDropdownItemHidden;
+ } else {
+ this.navigationItem = undefined;
}
- this.hasFocus = event.detail;
}
@Listen('keydown', {
@@ -294,6 +296,11 @@ export class Select {
event.stopPropagation();
event.preventDefault();
+ const focusItem = this.items.find(
+ (item) => document.activeElement === item.querySelector('button')
+ );
+ this.navigationItem = focusItem;
+
const selectItems = this.items.filter(
(i) => !i.classList.contains('d-none')
);
@@ -310,13 +317,12 @@ export class Select {
}
private setHoverEffectForNavigatedSelectItem() {
- this.items.forEach((item: HTMLIxSelectItemElement) => {
- item.hover = item === this.navigationItem;
- });
+ this.navigationItem?.querySelector('button').focus();
}
private filterItemsWithTypeahead() {
this.inputFilterText = this.inputRef.value;
+
if (this.inputFilterText) {
this.items.forEach((item) => {
item.classList.remove('d-none');
@@ -329,9 +335,8 @@ export class Select {
} else {
this.removeHiddenFromItems();
}
- this.isDropdownEmpty = this.items.every((item) =>
- item.classList.contains('d-none')
- );
+
+ this.isDropdownEmpty = this.isEveryDropdownItemHidden;
}
private removeHiddenFromItems() {
@@ -353,6 +358,22 @@ export class Select {
this.dropdownShow = false;
}
+ private onInputBlur(e) {
+ if (this.editable) {
+ return;
+ }
+
+ if (this.isSingleMode) {
+ if (this.dropdownShow && this.isDropdownEmpty) {
+ this.dropdownShow = false;
+ }
+ }
+
+ if (!this.dropdownShow && this.mode !== 'multiple') {
+ e.target['value'] = this.value;
+ }
+ }
+
private placeholderValue() {
if (this.editable) {
return this.i18nPlaceholderEditable;
@@ -411,6 +432,7 @@ export class Select {
placeholder={this.placeholderValue()}
value={this.inputValue}
ref={(ref) => (this.inputRef = ref)}
+ onBlur={(e) => this.onInputBlur(e)}
onInput={() => this.filterItemsWithTypeahead()}
/>
{this.allowClear &&
@@ -446,10 +468,7 @@ export class Select {
ref={(ref) => (this.dropdownRef = ref)}
show={this.dropdownShow}
class={{
- 'd-none':
- this.disabled ||
- this.readonly ||
- (this.isDropdownEmpty && !this.editable),
+ 'd-none': this.disabled || this.readonly,
}}
anchor={this.dropdownAnchor}
trigger={this.dropdownWrapperRef}
@@ -457,14 +476,14 @@ export class Select {
placement="auto-start"
overwriteDropdownStyle={async () => {
return {
- width: `${this.hostElement.clientWidth}px`,
+ minWidth: `${this.hostElement.clientWidth}px`,
};
}}
>
@@ -490,6 +509,11 @@ export class Select {
}}
>
)}
+ {this.isDropdownEmpty && !this.editable ? (
+
+ ) : (
+ ''
+ )}
);
diff --git a/packages/core/src/tests/dropdown-button/dropdown-button.e2e.ts b/packages/core/src/tests/dropdown-button/dropdown-button.e2e.ts
index 69899bec1e2..3b1b5ce3c9e 100644
--- a/packages/core/src/tests/dropdown-button/dropdown-button.e2e.ts
+++ b/packages/core/src/tests/dropdown-button/dropdown-button.e2e.ts
@@ -29,6 +29,8 @@ regressionTest.describe('basic', () => {
await page.waitForSelector('.dropdown.show');
- expect(await page.screenshot({ fullPage: true })).toMatchSnapshot();
+ expect(await page.screenshot({ fullPage: true })).toMatchSnapshot({
+ maxDiffPixelRatio: 0.01,
+ });
});
});
diff --git a/packages/vue/src/components.ts b/packages/vue/src/components.ts
index 9005045e4a6..d9157237b2f 100644
--- a/packages/vue/src/components.ts
+++ b/packages/vue/src/components.ts
@@ -489,6 +489,7 @@ export const IxSelect = /*@__PURE__*/ defineContainer('ix-select',
'i18nPlaceholder',
'i18nPlaceholderEditable',
'i18nSelectListHeader',
+ 'i18nNoMatches',
'hideListHeader',
'itemSelectionChange',
'addItem'