Skip to content

Commit

Permalink
feat: fix support options (#38968)
Browse files Browse the repository at this point in the history
* feat: fix support options

* feat: update package
  • Loading branch information
heiyu4585 authored and li-jia-nan committed Nov 25, 2022
1 parent 4ae1870 commit 22e3925
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 112 deletions.
20 changes: 20 additions & 0 deletions components/mentions/__tests__/index.test.tsx
Expand Up @@ -84,4 +84,24 @@ describe('Mentions', () => {
expect(wrapper.container.querySelectorAll('li.ant-mentions-dropdown-menu-item').length).toBe(1);
expect(wrapper.container.querySelectorAll('.bamboo-light').length).toBeTruthy();
});

it('do not lose label when use children Option', () => {
const wrapper = render(
<Mentions style={{ width: '100%' }}>
<Mentions.Option value="afc163">Afc163</Mentions.Option>
<Mentions.Option value="zombieJ">ZombieJ</Mentions.Option>
<Mentions.Option value="yesmeck">Yesmeck</Mentions.Option>
</Mentions>,
);
simulateInput(wrapper, '@');
const { container } = wrapper;
fireEvent.mouseEnter(container.querySelector('li.ant-mentions-dropdown-menu-item:last-child')!);
fireEvent.focus(container.querySelector('textarea')!);
act(() => {
jest.runAllTimers();
});
expect(
wrapper.container.querySelector('.ant-mentions-dropdown-menu-item-active')?.textContent,
).toBe('Yesmeck');
});
});
25 changes: 16 additions & 9 deletions components/mentions/demo/async.tsx
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useRef, useState } from 'react';
import { Mentions } from 'antd';
import debounce from 'lodash/debounce';

const { Option } = Mentions;
const App: React.FC = () => {
const [loading, setLoading] = useState(false);
const [users, setUsers] = useState<{ login: string; avatar_url: string }[]>([]);
Expand Down Expand Up @@ -36,14 +35,22 @@ const App: React.FC = () => {
};

return (
<Mentions style={{ width: '100%' }} loading={loading} onSearch={onSearch}>
{users.map(({ login, avatar_url: avatar }) => (
<Option key={login} value={login} className="antd-demo-dynamic-option">
<img src={avatar} alt={login} />
<span>{login}</span>
</Option>
))}
</Mentions>
<Mentions
style={{ width: '100%' }}
loading={loading}
onSearch={onSearch}
options={users.map(({ login, avatar_url: avatar }) => ({
key: login,
value: login,
className: 'antd-demo-dynamic-option',
label: (
<>
<img src={avatar} alt={login} />
<span>{login}</span>
</>
),
}))}
/>
);
};

Expand Down
25 changes: 18 additions & 7 deletions components/mentions/demo/autoSize.tsx
@@ -1,14 +1,25 @@
import React from 'react';
import { Mentions } from 'antd';

const { Option } = Mentions;

const App: React.FC = () => (
<Mentions autoSize style={{ width: '100%' }}>
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
<Option value="yesmeck">yesmeck</Option>
</Mentions>
<Mentions
autoSize
style={{ width: '100%' }}
options={[
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
{
value: 'yesmeck',
label: 'yesmeck',
},
]}
/>
);

export default App;
26 changes: 17 additions & 9 deletions components/mentions/demo/basic.tsx
@@ -1,14 +1,12 @@
import React from 'react';
import { Mentions } from 'antd';
import type { OptionProps } from 'antd/es/mentions';

const { Option } = Mentions;
import type { MentionsOptionProps } from 'antd/es/mentions';

const onChange = (value: string) => {
console.log('Change:', value);
};

const onSelect = (option: OptionProps) => {
const onSelect = (option: MentionsOptionProps) => {
console.log('select', option);
};

Expand All @@ -18,11 +16,21 @@ const App: React.FC = () => (
onChange={onChange}
onSelect={onSelect}
defaultValue="@afc163"
>
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
<Option value="yesmeck">yesmeck</Option>
</Mentions>
options={[
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
{
value: 'yesmeck',
label: 'yesmeck',
},
]}
/>
);

export default App;
47 changes: 36 additions & 11 deletions components/mentions/demo/form.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { Button, Form, Mentions } from 'antd';

const { Option, getMentions } = Mentions;
const { getMentions } = Mentions;

const App: React.FC = () => {
const [form] = Form.useForm();
Expand Down Expand Up @@ -36,11 +36,23 @@ const App: React.FC = () => {
wrapperCol={{ span: 16 }}
rules={[{ validator: checkMention }]}
>
<Mentions rows={1}>
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
<Option value="yesmeck">yesmeck</Option>
</Mentions>
<Mentions
rows={1}
options={[
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
{
value: 'yesmeck',
label: 'yesmeck',
},
]}
/>
</Form.Item>
<Form.Item
name="bio"
Expand All @@ -49,11 +61,24 @@ const App: React.FC = () => {
wrapperCol={{ span: 16 }}
rules={[{ required: true }]}
>
<Mentions rows={3} placeholder="You can use @ to ref user here">
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
<Option value="yesmeck">yesmeck</Option>
</Mentions>
<Mentions
rows={3}
placeholder="You can use @ to ref user here"
options={[
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
{
value: 'yesmeck',
label: 'yesmeck',
},
]}
/>
</Form.Item>
<Form.Item wrapperCol={{ span: 14, offset: 6 }}>
<Button htmlType="submit" type="primary">
Expand Down
25 changes: 18 additions & 7 deletions components/mentions/demo/placement.tsx
@@ -1,14 +1,25 @@
import React from 'react';
import { Mentions } from 'antd';

const { Option } = Mentions;

const App: React.FC = () => (
<Mentions style={{ width: '100%' }} placement="top">
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
<Option value="yesmeck">yesmeck</Option>
</Mentions>
<Mentions
style={{ width: '100%' }}
placement="top"
options={[
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
{
value: 'yesmeck',
label: 'yesmeck',
},
]}
/>
);

export default App;
15 changes: 6 additions & 9 deletions components/mentions/demo/prefix.tsx
@@ -1,8 +1,6 @@
import React, { useState } from 'react';
import { Mentions } from 'antd';

const { Option } = Mentions;

const MOCK_DATA = {
'@': ['afc163', 'zombiej', 'yesmeck'],
'#': ['1.0', '2.0', '3.0'],
Expand All @@ -23,13 +21,12 @@ const App: React.FC = () => {
placeholder="input @ to mention people, # to mention tag"
prefix={['@', '#']}
onSearch={onSearch}
>
{(MOCK_DATA[prefix] || []).map((value) => (
<Option key={value} value={value}>
{value}
</Option>
))}
</Mentions>
options={(MOCK_DATA[prefix] || []).map((value) => ({
key: value,
value,
label: value,
}))}
/>
);
};

Expand Down
31 changes: 17 additions & 14 deletions components/mentions/demo/readonly.tsx
@@ -1,25 +1,28 @@
import React from 'react';
import { Mentions } from 'antd';

const { Option } = Mentions;

const getOptions = () =>
['afc163', 'zombiej', 'yesmeck'].map((value) => (
<Option key={value} value={value}>
{value}
</Option>
));
const options = ['afc163', 'zombiej', 'yesmeck'].map((value) => ({
value,
key: value,
label: value,
}));

const App: React.FC = () => (
<>
<div style={{ marginBottom: 10 }}>
<Mentions style={{ width: '100%' }} placeholder="this is disabled Mentions" disabled>
{getOptions()}
</Mentions>
<Mentions
style={{ width: '100%' }}
placeholder="this is disabled Mentions"
disabled
options={options}
/>
</div>
<Mentions style={{ width: '100%' }} placeholder="this is readOnly Mentions" readOnly>
{getOptions()}
</Mentions>
<Mentions
style={{ width: '100%' }}
placeholder="this is readOnly Mentions"
readOnly
options={options}
/>
</>
);

Expand Down
18 changes: 12 additions & 6 deletions components/mentions/demo/render-panel.tsx
@@ -1,15 +1,21 @@
import React from 'react';
import { Mentions } from 'antd';

const { Option } = Mentions;

const { _InternalPanelDoNotUseOrYouWillBeFired: InternalMentions } = Mentions;

const options = [
{
value: 'afc163',
label: 'afc163',
},
{
value: 'zombieJ',
label: 'zombieJ',
},
];

const App: React.FC = () => (
<InternalMentions style={{ width: '100%' }} value="@">
<Option value="afc163">afc163</Option>
<Option value="zombieJ">zombieJ</Option>
</InternalMentions>
<InternalMentions style={{ width: '100%' }} value="@" options={options} />
);

export default App;

0 comments on commit 22e3925

Please sign in to comment.