Skip to content

Commit 6d38c46

Browse files
committed
[dropdown] refresh dropdown when items changed
1 parent 3db86ce commit 6d38c46

File tree

1 file changed

+15
-1
lines changed
  • src/components/form-inputs/dropdown

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { _DropdownBase } from './_base';
99
export class Dropdown extends _DropdownBase {
1010

1111
selectedItems = undefined
12+
_htmlItems = ''
1213

1314
createComponent(ch) {
1415
let css = 'ui selection dropdown'
@@ -20,11 +21,24 @@ export class Dropdown extends _DropdownBase {
2021
ch('input', { attrs: { type: 'hidden', name: this.name } }),
2122
ch('i', { 'class': 'dropdown icon' }),
2223
ch('div', { 'class': 'default text' }, this.placeholder),
23-
ch('div', { 'class': 'menu' }, this.$slots['default'])
24+
ch('div', { 'class': 'menu', 'ref': 'menu' }, this.$slots['default'])
2425
])
2526
}
2627

2728

29+
beforeUpdate() {
30+
// store dropdown items state
31+
this._htmlItems = (this.$refs['menu'] as HTMLDivElement).innerHTML
32+
}
33+
34+
updated() {
35+
// refresh dropdown when items has been changed
36+
if (this._htmlItems !== (this.$refs['menu'] as HTMLDivElement).innerHTML) {
37+
this.sui('refresh')
38+
}
39+
}
40+
41+
2842
mounted() {
2943

3044
var self = this;

0 commit comments

Comments
 (0)