fix: Unwanted width calculation in Dropdown (#15239)
This commit is contained in:
parent
1af9e2042f
commit
8724f1c4fa
|
|
@ -21,7 +21,7 @@ import { TooltipComponent as Tooltip } from "design-system";
|
||||||
import { isEllipsisActive } from "utils/helpers";
|
import { isEllipsisActive } from "utils/helpers";
|
||||||
import SegmentHeader from "components/ads/ListSegmentHeader";
|
import SegmentHeader from "components/ads/ListSegmentHeader";
|
||||||
import { useTheme } from "styled-components";
|
import { useTheme } from "styled-components";
|
||||||
import { findIndex, isArray } from "lodash";
|
import { debounce, findIndex, isArray } from "lodash";
|
||||||
import { TooltipComponent } from "design-system";
|
import { TooltipComponent } from "design-system";
|
||||||
import { SubTextPosition } from "components/constants";
|
import { SubTextPosition } from "components/constants";
|
||||||
import { DSEventTypes, emitDSEvent } from "utils/AppsmithUtils";
|
import { DSEventTypes, emitDSEvent } from "utils/AppsmithUtils";
|
||||||
|
|
@ -1149,12 +1149,36 @@ export default function Dropdown(props: DropdownProps) {
|
||||||
[isOpen, props.options, props.selected, selected, highlight],
|
[isOpen, props.options, props.selected, selected, highlight],
|
||||||
);
|
);
|
||||||
|
|
||||||
let dropdownWrapperWidth = "100%";
|
const [dropdownWrapperWidth, setDropdownWrapperWidth] = useState<string>(
|
||||||
|
"100%",
|
||||||
|
);
|
||||||
|
|
||||||
if (dropdownWrapperRef.current) {
|
const prevWidth = useRef(0);
|
||||||
const { width } = dropdownWrapperRef.current.getBoundingClientRect();
|
|
||||||
dropdownWrapperWidth = `${width}px`;
|
const onParentResize = useCallback(
|
||||||
}
|
debounce((entries) => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (dropdownWrapperRef.current) {
|
||||||
|
const width = entries[0].borderBoxSize?.[0].inlineSize;
|
||||||
|
if (typeof width === "number" && width !== prevWidth.current) {
|
||||||
|
prevWidth.current = width;
|
||||||
|
setDropdownWrapperWidth(`${width}px`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 300),
|
||||||
|
[dropdownWrapperRef.current],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const resizeObserver = new ResizeObserver(onParentResize);
|
||||||
|
if (dropdownWrapperRef.current && props.fillOptions)
|
||||||
|
resizeObserver.observe(dropdownWrapperRef.current);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
|
}, [dropdownWrapperRef.current, props.fillOptions]);
|
||||||
|
|
||||||
let dropdownHeight = props.isMultiSelect ? "auto" : "36px";
|
let dropdownHeight = props.isMultiSelect ? "auto" : "36px";
|
||||||
if (props.height) {
|
if (props.height) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ const mockObserveFn = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
window.IntersectionObserver = jest.fn().mockImplementation(mockObserveFn);
|
window.IntersectionObserver = jest.fn().mockImplementation(mockObserveFn);
|
||||||
|
window.ResizeObserver = jest.fn().mockImplementation(mockObserveFn);
|
||||||
|
|
||||||
// establish API mocking before all tests
|
// establish API mocking before all tests
|
||||||
beforeAll(() => server.listen());
|
beforeAll(() => server.listen());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user