diff --git a/CHANGELOG.md b/CHANGELOG.md index 078bf2223b..8bf3149441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### [146.4.2](https://github.com/Sage/carbon/compare/v146.4.1...v146.4.2) (2025-01-10) + + +### Bug Fixes + +* **select:** ensure select-list has correct box-shadow when placement is top ([cc035ce](https://github.com/Sage/carbon/commit/cc035ce0386794ecea571a7d5563668dc569c35a)), closes [#7125](https://github.com/Sage/carbon/issues/7125) + ### [146.4.1](https://github.com/Sage/carbon/compare/v146.4.0...v146.4.1) (2025-01-10) diff --git a/package-lock.json b/package-lock.json index 3c2d3141a5..721553dd49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "carbon-react", - "version": "146.4.1", + "version": "146.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "carbon-react", - "version": "146.4.1", + "version": "146.4.2", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 8f0c219d80..f2413e84ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "carbon-react", - "version": "146.4.1", + "version": "146.4.2", "description": "A library of reusable React components for easily building user interfaces.", "files": [ "lib", diff --git a/src/components/select/__internal__/select-list/select-list.component.tsx b/src/components/select/__internal__/select-list/select-list.component.tsx index 6ca2aed6bd..587343f31b 100644 --- a/src/components/select/__internal__/select-list/select-list.component.tsx +++ b/src/components/select/__internal__/select-list/select-list.component.tsx @@ -142,9 +142,11 @@ const SelectList = React.forwardRef( ) => { const [currentOptionsListIndex, setCurrentOptionsListIndex] = useState(-1); const [scrollbarWidth, setScrollbarWidth] = useState(0); + const [actualPlacement, setActualPlacement] = useState(listPlacement); const lastFilter = useRef(""); const listRef = useRef(null); const tableRef = useRef(null); + const listWrapperRef = useRef(null); const listActionButtonRef = useRef(null); const { blockScroll, allowScroll } = useScrollBlock(); const actionButtonHeight = useRef(0); @@ -648,6 +650,25 @@ const SelectList = React.forwardRef( [listWidth, flipEnabled], ); + // set the placement of the list based on the floating placement + const setPlacement = useCallback(() => { + if (isOpen) { + const floatingPlacement = listWrapperRef.current?.getAttribute( + "data-floating-placement", + ) as ListPlacement; + + setActualPlacement(floatingPlacement); + } + }, [isOpen]); + + useEffect(() => { + setPlacement(); + window.addEventListener("resize", setPlacement); + return () => { + window.removeEventListener("resize", setPlacement); + }; + }, [setPlacement]); + const loader = isLoading ? ( @@ -705,9 +726,11 @@ const SelectList = React.forwardRef( animationFrame > ` height: ${({ listHeight }) => `${listHeight}px`}; `; -const StyledSelectListContainer = styled.div< - Pick ->` +interface StyledSelectListContainerProps { + isLoading?: boolean; + placement?: string; +} + +const StyledSelectListContainer = styled.div` background-color: white; - box-shadow: var(--boxShadow100); + box-shadow: ${({ placement }) => + placement?.includes("top") + ? "0 -5px 5px 0 #00141e33, 0 -10px 10px 0 #00141e1a" + : "var(--boxShadow100)"}; animation: fadeIn 250ms ease-out; position: absolute; z-index: ${({ theme }) => theme.zIndex.popover}; diff --git a/src/components/select/filterable-select/filterable-select.stories.tsx b/src/components/select/filterable-select/filterable-select.stories.tsx index e4608ee7e7..3182a65665 100644 --- a/src/components/select/filterable-select/filterable-select.stories.tsx +++ b/src/components/select/filterable-select/filterable-select.stories.tsx @@ -55,27 +55,26 @@ Default.storyName = "Default"; export const ListPlacement: Story = () => { return ( - - - - + + ); }; ListPlacement.storyName = "List Placement"; diff --git a/src/components/select/multi-select/multi-select.stories.tsx b/src/components/select/multi-select/multi-select.stories.tsx index ddb368a757..ac0fee9962 100644 --- a/src/components/select/multi-select/multi-select.stories.tsx +++ b/src/components/select/multi-select/multi-select.stories.tsx @@ -46,27 +46,26 @@ Default.storyName = "Default"; export const ListPlacement: Story = () => { return ( - - - - + + ); }; ListPlacement.storyName = "List Placement"; diff --git a/src/components/select/simple-select/simple-select.pw.tsx b/src/components/select/simple-select/simple-select.pw.tsx index 881a8cc627..b85204c503 100644 --- a/src/components/select/simple-select/simple-select.pw.tsx +++ b/src/components/select/simple-select/simple-select.pw.tsx @@ -1057,6 +1057,67 @@ test.describe("SimpleSelect component", () => { }); }); + ( + ["top", "top-start", "top-end"] as SimpleSelectProps["listPlacement"][] + ).forEach((position) => { + test(`should render list with expected box-shadow when listPosition is ${position}`, async ({ + mount, + page, + }) => { + await mount( + , + ); + + await selectText(page).click(); + const listElement = selectListPosition(page); + await expect(listElement).toHaveCSS( + "box-shadow", + "rgba(0, 20, 30, 0.2) 0px -5px 5px 0px, rgba(0, 20, 30, 0.1) 0px -10px 10px 0px", + ); + }); + }); + + ( + [ + "bottom", + "bottom-start", + "bottom-end", + ] as SimpleSelectProps["listPlacement"][] + ).forEach((position) => { + test(`should render list with expected box-shadow when listPosition is ${position}`, async ({ + mount, + page, + }) => { + await mount(); + + await selectText(page).click(); + const listElement = selectListPosition(page); + await expect(listElement).toHaveCSS( + "box-shadow", + "rgba(0, 20, 30, 0.2) 0px 5px 5px 0px, rgba(0, 20, 30, 0.1) 0px 10px 10px 0px", + ); + }); + }); + + test("should update box-shadow when placement changes due to window resize", async ({ + mount, + page, + }) => { + await mount(); + + await selectText(page).click(); + const listElement = selectListPosition(page); + await expect(listElement).toHaveCSS( + "box-shadow", + "rgba(0, 20, 30, 0.2) 0px 5px 5px 0px, rgba(0, 20, 30, 0.1) 0px 10px 10px 0px", + ); + await page.setViewportSize({ width: 1200, height: 250 }); + await expect(listElement).toHaveCSS( + "box-shadow", + "rgba(0, 20, 30, 0.2) 0px -5px 5px 0px, rgba(0, 20, 30, 0.1) 0px -10px 10px 0px", + ); + }); + test("should have correct hover state of list option", async ({ mount, page, diff --git a/src/components/select/simple-select/simple-select.stories.tsx b/src/components/select/simple-select/simple-select.stories.tsx index 35be78e013..7925ae7058 100644 --- a/src/components/select/simple-select/simple-select.stories.tsx +++ b/src/components/select/simple-select/simple-select.stories.tsx @@ -100,27 +100,26 @@ IsOptional.storyName = "IsOptional"; export const ListPlacement: Story = () => { return ( - - - + ); }; ListPlacement.storyName = "List Placement";