A platform for community discussion. Free, open, simple.
FIX: filter UI overlapping with INPUT on small screens (#34426)
Sam5b05cee72085
diff --git a/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs b/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjsindex e820592c953..2f2d48cfba0 100644--- a/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs+++ b/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs@@ -232,7 +232,10 @@ export default class FilterNavigationMenu extends Component {data: this.trackedMenuListData,maxWidth: 2000,matchTriggerWidth: true,- visibilityOptimizer: VISIBILITY_OPTIMIZERS.AUTO_PLACEMENT,+ visibilityOptimizer: VISIBILITY_OPTIMIZERS.NONE,+ constrainHeightToViewport: true,+ crossAxisShift: false, // NOTE: this should not be needed, but is. Without it when shrinking window autocomplete renders on top of input+ minHeight: 80,});if (!this.suggestions.length) {diff --git a/app/assets/javascripts/float-kit/addon/lib/constants.js b/app/assets/javascripts/float-kit/addon/lib/constants.jsindex 7b763b19c88..f1db97fd7ad 100644--- a/app/assets/javascripts/float-kit/addon/lib/constants.js+++ b/app/assets/javascripts/float-kit/addon/lib/constants.js@@ -16,6 +16,7 @@ export const FLOAT_UI_PLACEMENTS = [export const VISIBILITY_OPTIMIZERS = {FLIP: "flip",AUTO_PLACEMENT: "autoPlacement",+ NONE: "none",};export const TOOLTIP = {diff --git a/app/assets/javascripts/float-kit/addon/lib/update-position.js b/app/assets/javascripts/float-kit/addon/lib/update-position.jsindex 6cc5f399cf5..5dd7a6e55ca 100644--- a/app/assets/javascripts/float-kit/addon/lib/update-position.js+++ b/app/assets/javascripts/float-kit/addon/lib/update-position.js@@ -24,37 +24,39 @@ const centerOffset = offset(({ rects }) => {});export async function updatePosition(trigger, content, options) {- const padding = options.padding ?? {- top: headerOffset(),- left: 10,- right: 10,- bottom: 10,- };+ const padding = getPadding(options);+ const detectOverflowOptions = buildDetectOverflowOptions(options, padding);+ const centered = isCenteredPlacement(options);- const detectOverflowOptions = {- padding: isTesting() ? 0 : padding,- boundary: options.boundary,- };+ const { middleware, arrowElement } = buildMiddleware(+ options,+ content,+ detectOverflowOptions+ );- // Determine which visibility optimizer middleware to use- const visibilityOptimizer =- options.visibilityOptimizer ?? VISIBILITY_OPTIMIZERS.FLIP;+ content.dataset.strategy = options.strategy || "absolute";- const visibilityOptimizerMiddleware =- visibilityOptimizer === VISIBILITY_OPTIMIZERS.AUTO_PLACEMENT- ? autoPlacement({- allowedPlacements: options.allowedPlacements ?? FLOAT_UI_PLACEMENTS,- ...detectOverflowOptions,- })- : flip({- fallbackPlacements: options.fallbackPlacements ?? FLOAT_UI_PLACEMENTS,- ...detectOverflowOptions,- });+ const result = await computePosition(trigger, content, {+ placement: centered ? "bottom" : options.placement,+ strategy: options.strategy || "absolute",+ middleware,+ });+ if (options.computePosition) {+ options.computePosition(content, {+ ...result,+ arrowElement,+ });+ } else {+ applyComputedPosition(content, result, arrowElement);+ }+}++function buildMiddleware(options, content, detectOverflowOptions) {const middleware = [];- const isCentered = options.placement === "center";+ const centered = isCenteredPlacement(options);- if (isCentered) {+ if (centered) {middleware.push(centerOffset);} else {middleware.push(offset(options.offset ?? 10));@@ -63,32 +65,20 @@ export async function updatePosition(trigger, content, options) {middleware.push(inline());}- middleware.push(visibilityOptimizerMiddleware);-- let limiter;- if (options.limitShift) {- limiter = limitShift(options.limitShift);- }- middleware.push(- shift({- padding: detectOverflowOptions.padding,- limiter,- crossAxis: true,- })+ const visibilityOptimizer = buildVisibilityOptimizerMiddleware(+ options,+ detectOverflowOptions);+ if (visibilityOptimizer) {+ middleware.push(visibilityOptimizer);+ }++ middleware.push(buildShiftMiddleware(options, detectOverflowOptions));}let arrowElement;if (options.arrow) {- arrowElement = content.querySelector(".arrow");-- if (!arrowElement) {- arrowElement = domFromString(- iconHTML("tippy-rounded-arrow", { class: "arrow" })- )[0];- content.appendChild(arrowElement);- }-+ arrowElement = ensureArrowElement(content);middleware.push(arrow({ element: arrowElement }));}@@ -96,65 +86,163 @@ export async function updatePosition(trigger, content, options) {middleware.push(hide({ padding: detectOverflowOptions.padding }));}- if (options.matchTriggerWidth) {- middleware.push(- size({- apply({ rects, elements }) {- Object.assign(elements.floating.style, {- width: `${rects.reference.width}px`,- });- },- })- );- } else if (options.matchTriggerMinWidth) {- middleware.push(- size({- apply({ rects, elements }) {- Object.assign(elements.floating.style, {- minWidth: `${rects.reference.width}px`,- });- },- })- );+ const matchSize = buildMatchSizeMiddleware(options);+ if (matchSize) {+ middleware.push(matchSize);}- content.dataset.strategy = options.strategy || "absolute";+ const constrainHeight = buildConstrainHeightMiddleware(+ options,+ detectOverflowOptions+ );+ if (constrainHeight) {+ middleware.push(constrainHeight);+ }- const { x, y, placement, middlewareData } = await computePosition(- trigger,- content,- {- placement: isCentered ? "bottom" : options.placement,- strategy: options.strategy || "absolute",- middleware,+ return { middleware, arrowElement };+}++function applyComputedPosition(content, result, arrowElement) {+ const { x, y, placement, middlewareData } = result;++ content.dataset.placement = placement;++ Object.assign(content.style, {+ left: `${x}px`,+ top: `${y}px`,+ visibility: middlewareData.hide?.referenceHidden ? "hidden" : "visible",+ });++ if (middlewareData.arrow && arrowElement) {+ const arrowX = middlewareData.arrow.x;+ const arrowY = middlewareData.arrow.y;++ Object.assign(arrowElement.style, {+ left: arrowX != null ? `${arrowX}px` : "",+ top: arrowY != null ? `${arrowY}px` : "",+ });+ }+}++function getPadding(options) {+ return (+ options.padding ?? {+ top: headerOffset(),+ left: 10,+ right: 10,+ bottom: 10,});+}- if (options.computePosition) {- options.computePosition(content, {- x,- y,- placement,- middlewareData,- arrowElement,+function buildDetectOverflowOptions(options, padding) {+ return {+ padding: isTesting() ? 0 : padding,+ boundary: options.boundary,+ };+}++function isCenteredPlacement(options) {+ return options.placement === "center";+}++function ensureArrowElement(content) {+ let arrowElement = content.querySelector(".arrow");+ if (!arrowElement) {+ arrowElement = domFromString(+ iconHTML("tippy-rounded-arrow", { class: "arrow" })+ )[0];+ content.appendChild(arrowElement);+ }+ return arrowElement;+}++function buildVisibilityOptimizerMiddleware(options, detectOverflowOptions) {+ const visibilityOptimizer =+ options.visibilityOptimizer ?? VISIBILITY_OPTIMIZERS.FLIP;++ if (visibilityOptimizer === VISIBILITY_OPTIMIZERS.NONE) {+ return null;+ }++ if (visibilityOptimizer === VISIBILITY_OPTIMIZERS.AUTO_PLACEMENT) {+ return autoPlacement({+ allowedPlacements: options.allowedPlacements ?? FLOAT_UI_PLACEMENTS,+ ...detectOverflowOptions,});- } else {- content.dataset.placement = placement;+ }++ return flip({+ fallbackPlacements: options.fallbackPlacements ?? FLOAT_UI_PLACEMENTS,+ ...detectOverflowOptions,+ });+}++function buildShiftMiddleware(options, detectOverflowOptions) {+ let limiter;+ if (options.limitShift) {+ limiter = limitShift(options.limitShift);+ }++ const crossAxis = options.crossAxisShift ?? true;++ return shift({+ padding: detectOverflowOptions.padding,+ limiter,+ crossAxis,+ });+}++function buildMatchSizeMiddleware(options) {+ if (options.matchTriggerWidth) {+ return size({+ apply({ rects, elements }) {+ Object.assign(elements.floating.style, {+ width: `${rects.reference.width}px`,+ });+ },+ });+ }- Object.assign(content.style, {- left: `${x}px`,- top: `${y}px`,- visibility: middlewareData.hide?.referenceHidden ? "hidden" : "visible",+ if (options.matchTriggerMinWidth) {+ return size({+ apply({ rects, elements }) {+ Object.assign(elements.floating.style, {+ minWidth: `${rects.reference.width}px`,+ });+ },});+ }- if (middlewareData.arrow && arrowElement) {- const arrowX = middlewareData.arrow.x;- const arrowY = middlewareData.arrow.y;+ return null;+}- Object.assign(arrowElement.style, {- left: arrowX != null ? `${arrowX}px` : "",- top: arrowY != null ? `${arrowY}px` : "",- });- }+function buildConstrainHeightMiddleware(options, detectOverflowOptions) {+ if (!options.constrainHeightToViewport) {+ return null;}++ return size({+ apply({ availableHeight, elements }) {+ const max = Math.max(50, (availableHeight ?? 0) - 4);+ const inner = elements.floating.querySelector(+ ".fk-d-menu__inner-content"+ );++ const hideElement =+ options.minHeight && availableHeight < options.minHeight;++ if (inner) {+ inner.style.display = hideElement ? "none" : "";+ Object.assign(inner.style, { maxHeight: `${max}px` });+ } else {+ elements.floating.style.display = hideElement ? "none" : "";+ Object.assign(elements.floating.style, {+ maxHeight: `${max}px`,+ overflow: "auto",+ });+ }+ },+ ...detectOverflowOptions,+ });}