diff --git a/packages/webawesome/docs/docs/resources/changelog.md b/packages/webawesome/docs/docs/resources/changelog.md
index ed5c3a974..235328747 100644
--- a/packages/webawesome/docs/docs/resources/changelog.md
+++ b/packages/webawesome/docs/docs/resources/changelog.md
@@ -14,7 +14,8 @@ Components with the Experimental badge sh
## Next
- Fixed a bug in `` that prevented the listbox from opening when options were preselected [issue:1883]
-- Fixed a bug in `` and `` that caused an error when removing a popup while it was opening
+- Fixed a bug in `` and `` that caused an error when removing a popup while it was opening [issue:1910]
+- Fixed a bug in `` and `` that caused errors when shadow DOM queries returned null [issue:1911]
## 3.1.0
diff --git a/packages/webawesome/src/components/dropdown/dropdown.ts b/packages/webawesome/src/components/dropdown/dropdown.ts
index b3a1a70e9..6d9c2c521 100644
--- a/packages/webawesome/src/components/dropdown/dropdown.ts
+++ b/packages/webawesome/src/components/dropdown/dropdown.ts
@@ -138,9 +138,9 @@ export default class WaDropdown extends WebAwesomeElement {
/** Gets all dropdown items slotted in the menu. */
private getItems(includeDisabled = false): WaDropdownItem[] {
- const items = this.defaultSlot
- .assignedElements({ flatten: true })
- .filter(el => el.localName === 'wa-dropdown-item') as WaDropdownItem[];
+ const items = (this.defaultSlot?.assignedElements({ flatten: true }) ?? []).filter(
+ el => el.localName === 'wa-dropdown-item',
+ ) as WaDropdownItem[];
return includeDisabled ? items : items.filter(item => !item.disabled);
}
@@ -165,9 +165,9 @@ export default class WaDropdown extends WebAwesomeElement {
/** Syncs item sizes with the dropdown's size property. */
private syncItemSizes() {
- const items = this.defaultSlot
- .assignedElements({ flatten: true })
- .filter(el => el.localName === 'wa-dropdown-item') as WaDropdownItem[];
+ const items = (this.defaultSlot?.assignedElements({ flatten: true }) ?? []).filter(
+ el => el.localName === 'wa-dropdown-item',
+ ) as WaDropdownItem[];
items.forEach(item => (item.size = this.size));
}
@@ -230,7 +230,7 @@ export default class WaDropdown extends WebAwesomeElement {
/** Shows the dropdown menu. This should only be called from within updated(). */
private async showMenu() {
const anchor = this.getTrigger();
- if (!anchor) return;
+ if (!anchor || !this.popup || !this.menu) return;
const showEvent = new WaShowEvent();
this.dispatchEvent(showEvent);
@@ -270,6 +270,8 @@ export default class WaDropdown extends WebAwesomeElement {
/** Hides the dropdown menu. This should only be called from within updated(). */
private async hideMenu() {
+ if (!this.popup || !this.menu) return;
+
const hideEvent = new WaHideEvent({ source: this });
this.dispatchEvent(hideEvent);
if (hideEvent.defaultPrevented) {
@@ -720,12 +722,12 @@ export default class WaDropdown extends WebAwesomeElement {
nativeButton.setAttribute('aria-haspopup', 'menu');
nativeButton.setAttribute('aria-expanded', this.open ? 'true' : 'false');
- this.menu.setAttribute('aria-expanded', 'false');
+ this.menu?.setAttribute('aria-expanded', 'false');
}
render() {
// On initial render, we want to use this.open, for everything else, we sync off of this.popup.active to get animations working.
- let active = this.hasUpdated ? this.popup.active : this.open;
+ let active = this.hasUpdated ? this.popup?.active : this.open;
return html`
{
- if (this.hoverBridge && this.anchorEl) {
+ if (this.hoverBridge && this.anchorEl && this.popup) {
const anchorRect = this.anchorEl.getBoundingClientRect();
const popupRect = this.popup.getBoundingClientRect();
const isVertical = this.placement.includes('top') || this.placement.includes('bottom');