ant-design/components/select/useBuiltinPlacements.tsx
二货爱吃白萝卜 8c094ba792
feat: ConfigProvider support config popupOverflow for scroll logic (#41676)
* feat: popupOverflow

* test: add test case

* docs: preview

* docs: update preview

* test: update test case
2023-04-07 10:17:00 +08:00

46 lines
1.0 KiB
TypeScript

import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
import type { PopupOverflow } from '../config-provider/context';
const getBuiltInPlacements = (popupOverflow?: PopupOverflow): Record<string, AlignType> => {
const htmlRegion: AlignType['htmlRegion'] = popupOverflow === 'scroll' ? 'scroll' : 'visible';
const sharedConfig = {
overflow: {
adjustX: true,
adjustY: true,
shiftY: true,
},
htmlRegion,
};
return {
bottomLeft: {
...sharedConfig,
points: ['tl', 'bl'],
offset: [0, 4],
},
bottomRight: {
...sharedConfig,
points: ['tr', 'br'],
offset: [0, 4],
},
topLeft: {
...sharedConfig,
points: ['bl', 'tl'],
offset: [0, -4],
},
topRight: {
...sharedConfig,
points: ['br', 'tr'],
offset: [0, -4],
},
};
};
export default function useBuiltinPlacements(
buildInPlacements?: BuildInPlacements,
popupOverflow?: PopupOverflow,
) {
return buildInPlacements || getBuiltInPlacements(popupOverflow);
}