Skip to content

Commit

Permalink
fix(cdk:popper): popper shouldn't update if reference is display none (
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Aug 14, 2023
1 parent 4ac4c5e commit cf83513
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/cdk/popper/src/middlewares/arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ export function arrow(arrowElement: HTMLElement): Middleware {
...rest,
name: 'IDUX_arrow',
async fn(middlewareArguments) {
const { reference } = middlewareArguments.elements

if (!(reference instanceof HTMLElement) || getComputedStyle(reference).display === 'none') {
return middlewareArguments
}

const res = (await arrowFn(middlewareArguments)) as { data: { x: number; y: number; centerOffset: number } }

const {
data: { x, y },
} = res

Object.assign(arrowElement.style, {
left: x != null ? `${x}px` : '',
top: y != null ? `${y}px` : '',
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk/popper/src/middlewares/refenceHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function checkParentsVisible(el: ReferenceElement): boolean {

let parent = el.parentElement
while (parent) {
if (!isVisibleElement(parent)) {
if (getComputedStyle(parent).display !== 'contents' && !isVisibleElement(parent)) {
return false
}

Expand Down
9 changes: 6 additions & 3 deletions packages/cdk/popper/src/middlewares/updatePlacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export function updatePlacement(updatePlacement: (value: PopperPlacement) => voi
fn(middlewareArguments) {
const {
placement,
elements: { floating },
elements: { floating, reference },
} = middlewareArguments
updatePlacement(camelCase(placement) as PopperPlacement)

floating.setAttribute('data-popper-placement', placement)
if (reference instanceof HTMLElement && getComputedStyle(reference).display !== 'none') {
updatePlacement(camelCase(placement) as PopperPlacement)
floating.setAttribute('data-popper-placement', placement)
}

return middlewareArguments
},
}
Expand Down

0 comments on commit cf83513

Please sign in to comment.