-
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom label render (#995)
* feat: support custom label render * fix: update tests & demo & doc * Update src/Select.tsx Co-authored-by: Amumu <yoyo837@hotmail.com> * fix: demo * fix: ci lint Signed-off-by: xliez <xliez@foxmail.com> * fix: hooks deps & format demo * test: 测试用例调整 * chore: fix lint Signed-off-by: xliez <xliez@foxmail.com> * test: 添加测试用例 --------- Signed-off-by: xliez <xliez@foxmail.com> Co-authored-by: Amumu <yoyo837@hotmail.com>
- Loading branch information
Showing
5 changed files
with
144 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,8 @@ | ||
--- | ||
title: custom-label | ||
nav: | ||
title: Demo | ||
path: /demo | ||
--- | ||
|
||
<code src="../examples/custom-label.tsx"></code> |
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,66 @@ | ||
/* eslint-disable no-console */ | ||
import Select, { Option } from 'rc-select'; | ||
import React from 'react'; | ||
import '../../assets/index.less'; | ||
|
||
const children = []; | ||
for (let i = 10; i < 36; i += 1) { | ||
children.push( | ||
<Option key={i.toString(36) + i} test={i}> | ||
{i.toString(36) + i} | ||
</Option>, | ||
); | ||
} | ||
|
||
const Test: React.FC = () => { | ||
const [value, setValue] = React.useState<string>('test'); | ||
|
||
return ( | ||
<div> | ||
<h2>custom label render</h2> | ||
|
||
<div> | ||
<Select | ||
placeholder="placeholder" | ||
style={{ width: 500 }} | ||
value={value} | ||
onChange={(val: string, option) => { | ||
console.log('change', val, option); | ||
setValue(val); | ||
}} | ||
onSelect={(val, option) => { | ||
console.log('selected', val, option); | ||
}} | ||
onDeselect={(val, option) => { | ||
console.log('deselected', val, option); | ||
}} | ||
tokenSeparators={[',']} | ||
labelRender={(props) => { | ||
const { label, value: _value } = props; | ||
const style: React.CSSProperties = { backgroundColor: 'red' }; | ||
if (label) { | ||
return _value; | ||
} else return <span style={style}>no this value in options</span>; | ||
}} | ||
onFocus={() => console.log('focus')} | ||
onBlur={() => console.log('blur')} | ||
> | ||
{children} | ||
</Select> | ||
</div> | ||
<p> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
setValue('test'); | ||
}} | ||
> | ||
set value as test | ||
</button> | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Test; | ||
/* eslint-enable */ |
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
9a7fc96
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
select – ./
select.vercel.app
select-react-component.vercel.app
select-git-master-react-component.vercel.app