Skip to content

Commit

Permalink
bug(ui) fix Select menu bottom placement (issue 67)
Browse files Browse the repository at this point in the history
* switch from `flip` to `autoPlacement` positioning strategy in headless ui middleware
  • Loading branch information
franzheidl committed Aug 13, 2024
1 parent d4014b6 commit af19f3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/ui-components/src/components/Select/Select.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Icon } from "../Icon/Icon.component"
import { Spinner } from "../Spinner/Spinner.component"
import { FormHint } from "../FormHint/FormHint.component"
import { Float } from "@headlessui-float/react"
import { flip, offset, shift, size } from "@floating-ui/react-dom"
import { autoPlacement, offset, shift, size } from "@floating-ui/react-dom"
import { usePortalRef } from "../PortalProvider/index"
import { createPortal } from "react-dom"
import "./select.scss"
Expand Down Expand Up @@ -170,8 +170,14 @@ export const Select = ({
// Headless-UI-Float Middleware
const middleware = [
offset(4),
shift(),
flip(),
autoPlacement((state) =>

Check failure on line 173 in packages/ui-components/src/components/Select/Select.component.js

View workflow job for this annotation

GitHub Actions / lint

'state' is defined but never used. Allowed unused args must match /^_/u
// Uncomment to examine Headless-UI-Floating middleware:
// console.log(state),
({
crossAxis: true,
allowedPlacements: ["bottom", "top"],
})
),
size({
boundary: "viewport",
apply({ availableWidth, availableHeight, elements }) {
Expand All @@ -182,6 +188,7 @@ export const Select = ({
})
},
}),
shift(),
]

// This function is used to determine what to render for the selected options in the Select Toggle in multi-select case.
Expand Down
23 changes: 23 additions & 0 deletions packages/ui-components/src/components/Select/Select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ ControlledTemplate.propTypes = {
children: PropTypes.node,
}

const BottomPositionTemplate = ({ parentStyles, children, ...args }) => (

Check failure on line 87 in packages/ui-components/src/components/Select/Select.stories.js

View workflow job for this annotation

GitHub Actions / lint

'parentStyles' is missing in props validation

Check failure on line 87 in packages/ui-components/src/components/Select/Select.stories.js

View workflow job for this annotation

GitHub Actions / lint

'children' is missing in props validation
<div style={parentStyles}>
Bottom Positioned Select
<Select {...args}>{children}</Select>
</div>
)

export const Default = {
render: Template,
args: {
Expand Down Expand Up @@ -535,3 +542,19 @@ export const MultiSelectWithOptionValuesAndLabels = {
],
},
}

export const BottomPositionedSelect = {
render: BottomPositionTemplate,
args: {
parentStyles: {
position: "absolute",
bottom: "0",
},
children: [
<SelectOption key="1" value="Option 1" />,
<SelectOption key="2" value="Option 2" />,
<SelectOption key="3" value="Option 3" />,
<SelectOption key="4" value="Option 4" />,
],
},
}

0 comments on commit af19f3a

Please sign in to comment.