Skip to content

Commit d58dbff

Browse files
franfaccinkzar
andauthored
Fix issue with inline parent elements (#528)
* Fix issue with inline parent elements * Update comments Co-authored-by: Dave Vandyke <[email protected]> * Update click-to-load.js - Remove reset of "inset" property when copying original styles. - Improve comments for skipping size check on "inline" parent elements. --------- Co-authored-by: francielefaccin <[email protected]> Co-authored-by: Dave Vandyke <[email protected]>
1 parent 0f00e5f commit d58dbff

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/features/click-to-load.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,14 @@ function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
617617
if (!placeholder.parentElement) {
618618
return
619619
}
620-
620+
const parentStyles = window.getComputedStyle(placeholder.parentElement)
621+
// Inline elements, like span or p, don't have a height value that we can use because they're
622+
// not a "block" like element with defined sizes. Because we skip this check on "inline"
623+
// parents, it might be necessary to traverse up the DOM tree until we find the nearest non
624+
// "inline" parent to get a reliable height for this check.
625+
if (parentStyles.display === 'inline') {
626+
return
627+
}
621628
const { height: placeholderHeight } = placeholder.getBoundingClientRect()
622629
const { height: parentHeight } = placeholder.parentElement.getBoundingClientRect()
623630

@@ -634,7 +641,7 @@ function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
634641
/** @type {HTMLElement?} */
635642
const innerDiv = shadowRoot.querySelector('.DuckDuckGoSocialContainer')
636643
if (innerDiv) {
637-
innerDiv.style.minHeight = ''
644+
innerDiv.style.minHeight = 'initial'
638645
innerDiv.style.maxHeight = parentHeight + 'px'
639646
innerDiv.style.overflow = 'hidden'
640647
}
@@ -831,6 +838,17 @@ function resizeElementToMatch (sourceElement, targetElement) {
831838
for (const key of stylesToCopy) {
832839
targetElement.style[key] = computedStyle[key]
833840
}
841+
842+
// If the parent element is very small (and its dimensions can be trusted) set a max height/width
843+
// to avoid the placeholder overflowing.
844+
if (computedStyle.display !== 'inline') {
845+
if (targetElement.style.maxHeight < computedStyle.height) {
846+
targetElement.style.maxHeight = 'initial'
847+
}
848+
if (targetElement.style.maxWidth < computedStyle.width) {
849+
targetElement.style.maxWidth = 'initial'
850+
}
851+
}
834852
}
835853

836854
/**

0 commit comments

Comments
 (0)