Skip to content

Commit b07700d

Browse files
author
Ruud Seberechts
committed
[Autocomplete] Only activate clear button plugin when there is a placeholder option
Placeholder is not necessarily the first option
1 parent 7984747 commit b07700d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Autocomplete/assets/dist/controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
227227
const plugins = {};
228228
const isMultiple = !this.selectElement || this.selectElement.multiple;
229229
if (!this.formElement.disabled && !isMultiple) {
230-
const firstOption = this.selectElement.options[0];
231-
if (firstOption && firstOption.value === '') {
230+
const placeholderOptions = Array.from(this.selectElement.options)
231+
.filter((option) => option.value === '');
232+
if (placeholderOptions.length) {
232233
plugins.clear_button = { title: '' };
233234
}
234235
}

src/Autocomplete/assets/src/controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ export default class extends Controller {
131131
const isMultiple = !this.selectElement || this.selectElement.multiple;
132132
if (!this.formElement.disabled && !isMultiple) {
133133
// Only activate clear button plugin when there is a placeholder option
134-
const firstOption = this.selectElement.options[0];
135-
if (firstOption && firstOption.value === '') {
134+
const placeholderOptions = Array.from(this.selectElement.options)
135+
.filter((option) => option.value === '');
136+
if (placeholderOptions.length) {
136137
plugins.clear_button = { title: '' };
137138
}
138139
}

0 commit comments

Comments
 (0)