Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/components/menu/Menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,21 @@ describe('solid-ui-menu syncItems', () => {

document.body.removeChild(menu)
})

it('propagates disabled state to dropdown items', async () => {
const menu = createMenu()

const child = document.createElement('div')
child.textContent = 'Disabled Item'
child.setAttribute('disabled', '')
menu.appendChild(child)

document.body.appendChild(menu)
await menu.updateComplete

const dropdownItem = menu.shadowRoot?.querySelector('wa-dropdown-item') as HTMLElement & { disabled?: boolean }
expect(dropdownItem?.disabled).toBe(true)

document.body.removeChild(menu)
})
})
14 changes: 10 additions & 4 deletions src/components/menu/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ export default class Menu extends WebComponent {
private accessor dropdown: WaDropdown | null = null;

@state()
private accessor items: { slot: string; }[] = []
private accessor items: { slot: string; disabled: boolean }[] = []

private observer: MutationObserver = new MutationObserver(() => this.syncItems())

connectedCallback () {
super.connectedCallback()

this.syncItems()
this.observer.observe(this, { childList: true })
this.observer.observe(this, {
childList: true,
attributes: true,
subtree: true,
attributeFilter: ['disabled', 'slot']
})
}

disconnectedCallback () {
Expand All @@ -52,7 +57,7 @@ export default class Menu extends WebComponent {

${this.items.map(
(item) =>
html`<wa-dropdown-item @click=${this.onItemClick}>
html`<wa-dropdown-item ?disabled=${item.disabled} @click=${this.onItemClick}>
<slot name=${item.slot}></slot>
</wa-dropdown-item>`
)}
Expand All @@ -69,12 +74,13 @@ export default class Menu extends WebComponent {

this.items = items.map((item, index) => {
const slotName = `menu-item-${index}`
const disabled = item.hasAttribute('disabled')

if (item.getAttribute('slot') !== slotName) {
item.setAttribute('slot', slotName)
}

return { slot: slotName }
return { slot: slotName, disabled }
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/file-explorer/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface FileExplorerContext {
soloPane?: boolean

onBack?: () => void
refresh?: () => void
deleteTargetUri?: string
openPane?: (subject: NamedNode, paneName: string) => void
handleSharingClick?: () => void

Expand Down
Loading