-
Notifications
You must be signed in to change notification settings - Fork 359
fix(Select): improved label filtering #3891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RylanBot
wants to merge
7
commits into
develop
Choose a base branch
from
rylan/feat/select/filterable
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c9e573
feat(Select): optimize custom node rendering
RylanBot a95f2db
refactor: optimize value display logic
RylanBot 8ec8e7d
fix(useSingle): update placeholder logic
RylanBot 259ed00
chore(Option): update deps import orders
RylanBot ba42885
fix(useSingle): improve label handling and typing state management
RylanBot 5766fce
chore(useSingle): rename variables for clarity
RylanBot 105862d
fix(Cascader): improve title handling
RylanBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,55 +1,73 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { Select } from 'tdesign-react'; | ||
| import { Select, Space } from 'tdesign-react'; | ||
|
|
||
| const { Option } = Select; | ||
|
|
||
| const options = [ | ||
| { label: '用户一', value: '1', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户二', value: '2', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户三', value: '3', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户四', value: '4', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户五', value: '5', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户六', value: '6', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户七', value: '7', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户八', value: '8', description: '这是一段用户描述信息,可自定义内容' }, | ||
| { label: '用户九', value: '9', description: '这是一段用户描述信息,可自定义内容' }, | ||
| ]; | ||
|
|
||
| const avatarUrl = 'https://tdesign.gtimg.com/site/avatar.jpg'; | ||
|
|
||
| export default function CustomOptions() { | ||
| const generateCustomContent = (index: number) => ( | ||
| <div style={{ display: 'flex', padding: '8px 0' }}> | ||
| <img | ||
| src="https://tdesign.gtimg.com/site/avatar.jpg" | ||
| style={{ | ||
| maxWidth: '40px', | ||
| borderRadius: '50%', | ||
| }} | ||
| /> | ||
| <div style={{ marginLeft: '16px' }}> | ||
| <div>用户{index}</div> | ||
| <div | ||
| style={{ | ||
| fontSize: '13px', | ||
| color: 'var(--td-gray-color-9)', | ||
| }} | ||
| > | ||
| 这是一段用户描述信息,可自定义内容 | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| const createOption = (index: number) => { | ||
| const label = `用户${index}`; | ||
| return { | ||
| label, | ||
| value: index.toString(), | ||
| description: '这是一段用户描述信息,可自定义内容', | ||
| }; | ||
| }; | ||
|
|
||
| const options1 = Array.from({ length: 5 }, (_, index) => ({ | ||
| ...createOption(index + 1), | ||
| })); | ||
|
|
||
| const options2 = Array.from({ length: 5 }, (_, index) => ({ | ||
| ...createOption(index + 1), | ||
| content: generateCustomContent(index + 1), | ||
| })); | ||
|
|
||
| function CustomOptions() { | ||
| const [value, setValue] = useState('1'); | ||
| const onChange = (value: string) => { | ||
| setValue(value); | ||
| }; | ||
|
|
||
| return ( | ||
| <Select value={value} onChange={onChange} style={{ width: '300px' }} clearable> | ||
| {options.map((option, idx) => ( | ||
| <Option style={{ height: '60px' }} key={idx} value={option.value} label={option.label}> | ||
| <div style={{ display: 'flex' }}> | ||
| <img | ||
| src={avatarUrl} | ||
| style={{ | ||
| maxWidth: '40px', | ||
| borderRadius: '50%', | ||
| }} | ||
| /> | ||
| <div style={{ marginLeft: '16px' }}> | ||
| <div>{option.label}</div> | ||
| <div | ||
| style={{ | ||
| fontSize: '13px', | ||
| color: 'var(--td-gray-color-9)', | ||
| }} | ||
| > | ||
| {option.description} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </Option> | ||
| ))} | ||
| </Select> | ||
| <Space size="150px"> | ||
| <Space direction="vertical"> | ||
| <strong>法一:使用插槽</strong> | ||
| <Select value={value} onChange={onChange} clearable> | ||
| {options1.map((option, idx) => ( | ||
| <Option style={{ height: '60px' }} key={idx} value={option.value} label={option.label}> | ||
| {generateCustomContent(idx + 1)} | ||
| </Option> | ||
| ))} | ||
| </Select> | ||
| </Space> | ||
| <Space direction="vertical"> | ||
| <strong>法二:使用 `content` 属性</strong> | ||
| <Select options={options2} value={value} onChange={onChange} clearable style={{ width: 200 }} /> | ||
| </Space> | ||
| </Space> | ||
| ); | ||
| } | ||
|
|
||
| export default CustomOptions; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.