Add configurable dropdown to popovers to allow styling without needing data-cy
This commit is contained in:
parent
4e9d952b52
commit
f753116af4
|
@ -1,6 +1,6 @@
|
||||||
export default function positionDropdown(
|
export default function positionDropdown(
|
||||||
element,
|
element,
|
||||||
{ anchor, align, maxWidth, useAnchorWidth }
|
{ anchor, align, maxWidth, useAnchorWidth, offset = 5 }
|
||||||
) {
|
) {
|
||||||
const update = () => {
|
const update = () => {
|
||||||
if (!anchor) {
|
if (!anchor) {
|
||||||
|
@ -20,9 +20,9 @@ export default function positionDropdown(
|
||||||
if (align === "right-outside") {
|
if (align === "right-outside") {
|
||||||
styles.top = anchorBounds.top
|
styles.top = anchorBounds.top
|
||||||
} else if (window.innerHeight - anchorBounds.bottom < 100) {
|
} else if (window.innerHeight - anchorBounds.bottom < 100) {
|
||||||
styles.top = anchorBounds.top - elementBounds.height - 5
|
styles.top = anchorBounds.top - elementBounds.height - offset
|
||||||
} else {
|
} else {
|
||||||
styles.top = anchorBounds.bottom + 5
|
styles.top = anchorBounds.bottom + offset
|
||||||
styles.maxHeight = window.innerHeight - anchorBounds.bottom - 20
|
styles.maxHeight = window.innerHeight - anchorBounds.bottom - 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ export default function positionDropdown(
|
||||||
if (align === "right") {
|
if (align === "right") {
|
||||||
styles.left = anchorBounds.left + anchorBounds.width - elementBounds.width
|
styles.left = anchorBounds.left + anchorBounds.width - elementBounds.width
|
||||||
} else if (align === "right-outside") {
|
} else if (align === "right-outside") {
|
||||||
styles.left = anchorBounds.right + 10
|
styles.left = anchorBounds.right + offset
|
||||||
} else {
|
} else {
|
||||||
styles.left = anchorBounds.left
|
styles.left = anchorBounds.left
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
export let open = false
|
export let open = false
|
||||||
export let useAnchorWidth = false
|
export let useAnchorWidth = false
|
||||||
export let dismissible = true
|
export let dismissible = true
|
||||||
|
export let offset = 5
|
||||||
|
|
||||||
$: target = portalTarget || getContext(Context.PopoverRoot) || ".spectrum"
|
$: target = portalTarget || getContext(Context.PopoverRoot) || ".spectrum"
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@
|
||||||
align,
|
align,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
useAnchorWidth,
|
useAnchorWidth,
|
||||||
|
offset,
|
||||||
}}
|
}}
|
||||||
use:clickOutside={{
|
use:clickOutside={{
|
||||||
callback: dismissible ? handleOutsideClick : () => {},
|
callback: dismissible ? handleOutsideClick : () => {},
|
||||||
|
|
Loading…
Reference in New Issue