Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk:popper): popper shouldn't update if reference is display none #1653

Merged
merged 1 commit into from
Aug 14, 2023
Merged
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: 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