Skip to content

Commit

Permalink
added “auto” option for enableCollisionDetection + “limiter” for `s…
Browse files Browse the repository at this point in the history
…hift` middleware
  • Loading branch information
didoo committed Apr 16, 2024
1 parent 113a77d commit 87c1405
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/components/src/modifiers/hds-anchored-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import { modifier } from 'ember-modifier';
import { assert } from '@ember/debug';

import {
arrow,
autoUpdate,
computePosition,
offset,
flip,
shift,
limitShift,
autoPlacement,
arrow,
// ---
// this could be used in the future if we want to give consumers an option to hide the "floating" element when the "anchor" hides from the viewport
// see: https://floating-ui.com/docs/hide
// hide,
offset,
shift,
// ---
// this could be used in the future if we want to give consumers an option to:
// - let the "floating" element auto-resize when there is not enough space (usually vertical) in the viewport to contain the entire "floating" element
// - let the "floating" element match the width of the "trigger" (it may have min/max width/heigh via CSS too)
// see: https://floating-ui.com/docs/size
// notice: below you can find a preliminary code implementation that was tested and worked relatively well
// size,
// ---
} from '@floating-ui/dom';

export const DEFAULT_PLACEMENT = 'bottom';
Expand All @@ -43,7 +48,8 @@ export const getFloatingUIOptions = (options) => {
strategy = 'absolute', // we don't need to use `fixed` if we use the Popover API for the "floating" element (it puts the element in the `top-layer`)
offsetOptions,
flipOptions = { padding: 8 },
shiftOptions = { padding: 8 },
shiftOptions = { padding: 8, limiter: limitShift() },
autoPlacementOptions = { padding: 8 },
middlewareExtra = [],
enableCollisionDetection,
arrowOptions,
Expand All @@ -58,6 +64,7 @@ export const getFloatingUIOptions = (options) => {

// https://floating-ui.com/docs/flip
// https://floating-ui.com/docs/shift
// https://floating-ui.com/docs/autoPlacement
if (
enableCollisionDetection === true ||
enableCollisionDetection === 'flip'
Expand All @@ -70,6 +77,9 @@ export const getFloatingUIOptions = (options) => {
) {
middleware.push(shift(shiftOptions));
}
if (enableCollisionDetection === 'auto') {
middleware.push(autoPlacement(autoPlacementOptions));
}

// https://floating-ui.com/docs/arrow
if (arrowOptions) {
Expand Down

0 comments on commit 87c1405

Please sign in to comment.