diff --git a/src/components/FwbDropdown/composables/useDropdownClasses.ts b/src/components/FwbDropdown/composables/useDropdownClasses.ts index aa0e1c16..df544f0a 100644 --- a/src/components/FwbDropdown/composables/useDropdownClasses.ts +++ b/src/components/FwbDropdown/composables/useDropdownClasses.ts @@ -53,6 +53,26 @@ export function useDropdownClasses (props: UseDropdownClassesProps): { placementStyles.value = placementCalculators[props.placement.value](boundingRect) } + // Watch for changes in the content element, and recalculate placement classes + // to ensure the dropdown is always positioned correctly + const observer = new MutationObserver(() => { + calculatePlacementClasses() + }) + + watch( + props.contentRef, + (value) => { + if (value) { + observer.observe(value, { + childList: true, + subtree: true, + }) + } else { + observer.disconnect() + } + }, + ) + const contentClasses = computed(() => { return classNames( defaultDropdownClasses,