forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lessPlugin
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
order: 22 | ||
title: | ||
zh-CN: 隐藏已选择选项 | ||
en-US: Hide Already Selected | ||
--- | ||
|
||
## zh-CN | ||
|
||
隐藏下拉列表中已选择的选项。 | ||
|
||
## en-US | ||
|
||
Hide already selected options in the dropdown. | ||
|
||
````jsx | ||
import { Select } from 'antd'; | ||
|
||
const OPTIONS = ['Apples', 'Nails', 'Bananas', 'Helicopters']; | ||
|
||
class SelectWithHiddenSelectedOptions extends React.Component { | ||
state = { | ||
selectedItems: [], | ||
}; | ||
|
||
handleChange = selectedItems => { | ||
this.setState({ selectedItems }); | ||
}; | ||
|
||
render() { | ||
const { selectedItems } = this.state; | ||
const filteredOptions = OPTIONS.filter(o => !selectedItems.includes(o)); | ||
return ( | ||
<Select | ||
mode="multiple" | ||
placeholder="Inserted are removed" | ||
value={selectedItems} | ||
onChange={this.handleChange} | ||
style={{ width: '100%' }} | ||
> | ||
{filteredOptions.map(item => ( | ||
<Select.Option key={item} value={item}> | ||
{item} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(<SelectWithHiddenSelectedOptions />, mountNode); | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters