Skip to content

Commit da79829

Browse files
committed
[dropdown] bug fix force selection
1 parent 81742f7 commit da79829

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

dist/vue-typed-ui.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,15 +1497,19 @@ var Dropdown = function (_DropdownBase2) {
14971497
$(this.$el).find('input.search').on('blur', function (e) {
14981498
var text = $(e.target).val();
14991499
if (text) {
1500-
text = text.trim().toUpperCase();
1501-
var val = _this2.sui('get value');
1502-
$(_this2.$el).find('.menu').children('.item').each(function (i, el) {
1503-
if (el.textContent.trim().toUpperCase().startsWith(text)) {
1504-
val = $(el).data('value');
1505-
}
1506-
});
1507-
_this2.sui('set selected', val);
1508-
$(e.target).val('');
1500+
(function () {
1501+
text = text.trim().toUpperCase();
1502+
var val = _this2.sui('get value');
1503+
var foundFirstMatch = false;
1504+
$(_this2.$el).find('.menu').children('.item').each(function (i, el) {
1505+
if (!foundFirstMatch && el.textContent.trim().toUpperCase().startsWith(text)) {
1506+
val = $(el).data('value');
1507+
foundFirstMatch = true;
1508+
}
1509+
});
1510+
_this2.sui('set selected', val);
1511+
$(e.target).val('');
1512+
})();
15091513
}
15101514
});
15111515
// make up data validate attr

src/components/form-inputs/dropdown/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ export class Dropdown extends _DropdownBase {
7272
if (text) {
7373
text = text.trim().toUpperCase()
7474
let val = this.sui('get value')
75-
75+
let foundFirstMatch = false
7676
$(this.$el).find('.menu').children('.item').each(function (i, el) {
77-
if (el.textContent.trim().toUpperCase().startsWith(text)) {
77+
if (!foundFirstMatch && el.textContent.trim().toUpperCase().startsWith(text)) {
7878
val = $(el).data('value')
79+
foundFirstMatch = true
7980
}
8081
})
8182

0 commit comments

Comments
 (0)