Browse Source

enhance: auto align logic (#43556)

* enhance: auto align logic

* test: update snapshot

* chore: update snapshot

* chore: fix demo
pull/43575/head
二货爱吃白萝卜 1 year ago
committed by GitHub
parent
commit
4f099742b8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 291
      components/select/__tests__/__snapshots__/demo-extend.test.ts.snap
  2. 193
      components/select/__tests__/__snapshots__/demo.test.tsx.snap
  3. 7
      components/select/demo/placement-debug.md
  4. 59
      components/select/demo/placement-debug.tsx
  5. 1
      components/select/index.en-US.md
  6. 1
      components/select/index.zh-CN.md
  7. 5
      components/select/useBuiltinPlacements.tsx

291
components/select/__tests__/__snapshots__/demo-extend.test.ts.snap

@ -6656,6 +6656,297 @@ Array [
]
`;
exports[`renders components/select/demo/placement-debug.tsx extend context correctly 1`] = `
<div
style="height: 100%; min-height: 500px; display: flex; flex-direction: column; justify-content: center; align-items: center; position: relative;"
>
<div
class="ant-space ant-space-horizontal ant-space-align-center"
style="position: absolute; top: 0px; left: 50%; transform: translateX(-50%);"
>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
<div
class="ant-radio-group ant-radio-group-outline"
>
<label
class="ant-radio-button-wrapper ant-radio-button-wrapper-checked"
>
<span
class="ant-radio-button ant-radio-button-checked"
>
<input
checked=""
class="ant-radio-button-input"
type="radio"
value="topLeft"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
TL
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="topRight"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
TR
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="bottomLeft"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
BL
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="bottomRight"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
BR
</span>
</label>
</div>
</div>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
<button
aria-checked="false"
class="ant-switch"
role="switch"
type="button"
>
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
>
<span
class="ant-switch-inner-checked"
/>
<span
class="ant-switch-inner-unchecked"
/>
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Random
</span>
</button>
</div>
</div>
<div
class="ant-select ant-select-single ant-select-show-arrow"
style="width: 120px;"
>
<div
class="ant-select-selector"
>
<span
class="ant-select-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="false"
aria-haspopup="listbox"
aria-owns="rc_select_TEST_OR_SSR_list"
autocomplete="off"
class="ant-select-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
<span
class="ant-select-selection-placeholder"
/>
</div>
<div
class="ant-select-dropdown ant-slide-down-appear ant-slide-down-appear-prepare ant-slide-down ant-select-dropdown-placement-topLeft"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; width: 200px;"
>
<div>
<div
id="rc_select_TEST_OR_SSR_list"
role="listbox"
style="height: 0px; width: 0px; overflow: hidden;"
>
<div
aria-label="Option 0"
aria-selected="false"
id="rc_select_TEST_OR_SSR_list_0"
role="option"
>
0
</div>
<div
aria-label="Option 1"
aria-selected="false"
id="rc_select_TEST_OR_SSR_list_1"
role="option"
>
1
</div>
</div>
<div
class="rc-virtual-list"
style="position: relative;"
>
<div
class="rc-virtual-list-holder"
style="max-height: 256px; overflow-y: auto;"
>
<div>
<div
class="rc-virtual-list-holder-inner"
style="display: flex; flex-direction: column;"
>
<div
aria-selected="false"
class="ant-select-item ant-select-item-option ant-select-item-option-active"
title="Option 0"
>
<div
class="ant-select-item-option-content"
>
Option 0
</div>
<span
aria-hidden="true"
class="ant-select-item-option-state"
style="user-select: none;"
unselectable="on"
/>
</div>
<div
aria-selected="false"
class="ant-select-item ant-select-item-option"
title="Option 1"
>
<div
class="ant-select-item-option-content"
>
Option 1
</div>
<span
aria-hidden="true"
class="ant-select-item-option-state"
style="user-select: none;"
unselectable="on"
/>
</div>
<div
aria-selected="false"
class="ant-select-item ant-select-item-option"
title="Option 2"
>
<div
class="ant-select-item-option-content"
>
Option 2
</div>
<span
aria-hidden="true"
class="ant-select-item-option-state"
style="user-select: none;"
unselectable="on"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select: none;"
unselectable="on"
>
<span
aria-label="down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
aria-hidden="true"
data-icon="down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"
/>
</svg>
</span>
</span>
</div>
</div>
`;
exports[`renders components/select/demo/responsive.tsx extend context correctly 1`] = `
<div
class="ant-space ant-space-vertical"

193
components/select/__tests__/__snapshots__/demo.test.tsx.snap

@ -2158,6 +2158,199 @@ Array [
]
`;
exports[`renders components/select/demo/placement-debug.tsx correctly 1`] = `
<div
style="height:100%;min-height:500px;display:flex;flex-direction:column;justify-content:center;align-items:center;position:relative"
>
<div
class="ant-space ant-space-horizontal ant-space-align-center"
style="position:absolute;top:0;left:50%;transform:translateX(-50%)"
>
<div
class="ant-space-item"
style="margin-right:8px"
>
<div
class="ant-radio-group ant-radio-group-outline"
>
<label
class="ant-radio-button-wrapper ant-radio-button-wrapper-checked"
>
<span
class="ant-radio-button ant-radio-button-checked"
>
<input
checked=""
class="ant-radio-button-input"
type="radio"
value="topLeft"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
TL
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="topRight"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
TR
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="bottomLeft"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
BL
</span>
</label>
<label
class="ant-radio-button-wrapper"
>
<span
class="ant-radio-button"
>
<input
class="ant-radio-button-input"
type="radio"
value="bottomRight"
/>
<span
class="ant-radio-button-inner"
/>
</span>
<span>
BR
</span>
</label>
</div>
</div>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button
aria-checked="false"
class="ant-switch"
role="switch"
type="button"
>
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
>
<span
class="ant-switch-inner-checked"
/>
<span
class="ant-switch-inner-unchecked"
/>
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Random
</span>
</button>
</div>
</div>
<div
class="ant-select ant-select-single ant-select-show-arrow"
style="width:120px"
>
<div
class="ant-select-selector"
>
<span
class="ant-select-selection-search"
>
<input
aria-activedescendant="undefined_list_0"
aria-autocomplete="list"
aria-controls="undefined_list"
aria-expanded="false"
aria-haspopup="listbox"
aria-owns="undefined_list"
autocomplete="off"
class="ant-select-selection-search-input"
readonly=""
role="combobox"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
<span
class="ant-select-selection-placeholder"
/>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select:none;-webkit-user-select:none"
unselectable="on"
>
<span
aria-label="down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
aria-hidden="true"
data-icon="down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"
/>
</svg>
</span>
</span>
</div>
</div>
`;
exports[`renders components/select/demo/responsive.tsx correctly 1`] = `
<div
class="ant-space ant-space-vertical"

7
components/select/demo/placement-debug.md

@ -0,0 +1,7 @@
## zh-CN
可以通过 `placement` 手动指定弹出的位置。
## en-US
You can manually specify the position of the popup via `placement`.

59
components/select/demo/placement-debug.tsx

@ -0,0 +1,59 @@
import React, { useState } from 'react';
import type { RadioChangeEvent } from 'antd';
import { Button, Radio, Select, Space, Switch } from 'antd';
import type { SelectCommonPlacement } from 'antd/es/_util/motion';
const randomOptions = (count?: number) => {
const length = count ?? Math.floor(Math.random() * 5) + 1;
// Random 1 ~ 5 options
return Array.from({ length }).map((_, index) => ({
value: index,
label: `Option ${index}`,
}));
};
const App: React.FC = () => {
const [placement, SetPlacement] = useState<SelectCommonPlacement>('topLeft');
const [open, setOpen] = useState(false);
const [options, setOptions] = useState(() => randomOptions(3));
const placementChange = (e: RadioChangeEvent) => {
SetPlacement(e.target.value);
};
return (
<div
style={{
height: '100%',
minHeight: 500,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
position: 'relative',
}}
>
<Space style={{ position: 'absolute', top: 0, left: '50%', transform: 'translateX(-50%)' }}>
<Radio.Group value={placement} onChange={placementChange}>
<Radio.Button value="topLeft">TL</Radio.Button>
<Radio.Button value="topRight">TR</Radio.Button>
<Radio.Button value="bottomLeft">BL</Radio.Button>
<Radio.Button value="bottomRight">BR</Radio.Button>
</Radio.Group>
<Switch checked={open} onChange={() => setOpen((o) => !o)} />
<Button onClick={() => setOptions(randomOptions())}>Random</Button>
</Space>
<Select
open={open}
style={{ width: 120 }}
placement={placement}
options={options}
popupMatchSelectWidth={200}
/>
</div>
);
};
export default App;

1
components/select/index.en-US.md

@ -40,6 +40,7 @@ Select component to select value from options.
<code src="./demo/big-data.tsx">Big Data</code>
<code src="./demo/status.tsx">Status</code>
<code src="./demo/placement.tsx">Placement</code>
<code src="./demo/placement-debug.tsx" debug>Dynamic Height</code>
<code src="./demo/debug.tsx" debug>4.0 Debug</code>
<code src="./demo/render-panel.tsx" debug>\_InternalPanelDoNotUseOrYouWillBeFired</code>
<code src="./demo/option-label-center.tsx" debug>Options label Centered</code>

1
components/select/index.zh-CN.md

@ -41,6 +41,7 @@ demo:
<code src="./demo/big-data.tsx">大数据</code>
<code src="./demo/status.tsx">自定义状态</code>
<code src="./demo/placement.tsx">弹出位置</code>
<code src="./demo/placement-debug.tsx" debug>动态高度</code>
<code src="./demo/debug.tsx" debug>4.0 Debug</code>
<code src="./demo/render-panel.tsx" debug>\_InternalPanelDoNotUseOrYouWillBeFired</code>
<code src="./demo/option-label-center.tsx" debug>选项文本居中</code>

5
components/select/useBuiltinPlacements.tsx

@ -4,13 +4,16 @@ import type { PopupOverflow } from '../config-provider/context';
const getBuiltInPlacements = (popupOverflow?: PopupOverflow): Record<string, AlignType> => {
const htmlRegion: AlignType['htmlRegion'] = popupOverflow === 'scroll' ? 'scroll' : 'visible';
const sharedConfig = {
const sharedConfig: AlignType = {
overflow: {
adjustX: true,
adjustY: true,
shiftY: true,
},
htmlRegion,
_experimental: {
dynamicInset: true,
},
};
return {

Loading…
Cancel
Save