Skip to content

Commit

Permalink
Hide dropdown none option when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
hjr265 committed Feb 22, 2024
1 parent 9742b56 commit be69beb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/widgets/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ class Dropdown {
const menu = dom.$('.dropdown__menu', this.el)
for (const el of dom.$$('.dropdown__item', menu)) dom.detach(el)

const select = dom.$('select', this.el)

const addItem = (data) => {
const { label, value, empty, ...rest } = data

const item = this.makeItem(data)
menu.appendChild(item)

if (dom.hasClass(this.el, '-select')) {
const select = dom.$('select', this.el)
if (select) {
dom.on(item, 'click', () => {
if (empty) {
select.innerHTML = ''
Expand Down Expand Up @@ -133,7 +134,8 @@ class Dropdown {
}
}

addItem({ label: 'None', value: '', empty: true })
if (select && (select.multiple || dom.$('option[data-empty]', select))) addItem({ label: 'None', value: '', empty: true })

for (const item of items) addItem({ ...item, label: item.text, value: item.id })

this.reposition()
Expand Down

0 comments on commit be69beb

Please sign in to comment.