-
Notifications
You must be signed in to change notification settings - Fork 296
refactor(fixednav): 优化组件徽标的实现方式,解决原有不对称问题 #3061
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useConfig } from '@/packages/configprovider' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FixedNavProps } from './types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defaultOverlayProps } from '@/packages/overlay/overlay' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Badge from '@/packages/badge/index' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const defaultProps: FixedNavProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...defaultOverlayProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +59,23 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| className | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const renderListItem = (item: any, index: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={`${classPrefix}-list-item`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={(event) => onSelect(item, event)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={item.id || index} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {React.isValidElement(item.icon) ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| item.icon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <img src={item.icon} alt="" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className={`${classPrefix}-list-text`}>{item.text}</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={classes} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,19 +97,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className={`${classPrefix}-list`}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {list.map((item: any, index) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={`${classPrefix}-list-item`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={(event) => onSelect(item, event)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={item.id || index} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {React.isValidElement(item.icon) ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| item.icon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {item.num ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Badge value={item.num} top={8} right={6}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {renderListItem(item, index)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Badge> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <img src={item.icon} alt="" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <>{renderListItem(item, index)}</> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className={`${classPrefix}-list-text`}>{item.text}</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {item.num && <div className="b">{item.num}</div>} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+100
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修复 React Fragment 中缺少 key 属性的问题 在使用列表渲染时,每个 React Fragment 都需要添加 key 属性。 建议使用以下修复方案: return (
- <>
+ <React.Fragment key={item.id || index}>
{item.num ? (
- <Badge value={item.num} top={8} right={6}>
+ <Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
{renderListItem(item, index)}
</Badge>
) : (
- <>{renderListItem(item, index)}</>
+ <React.Fragment key={`item-${item.id || index}`}>{renderListItem(item, index)}</React.Fragment>
)}
- </>
+ </React.Fragment>
)📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 102-102: Missing key property for this element in iterable. The order of the items may change, and having a key can help React identify which item was moved. (lint/correctness/useJsxKeyInIterable) [error] 106-106: Missing key property for this element in iterable. The order of the items may change, and having a key can help React identify which item was moved. (lint/correctness/useJsxKeyInIterable) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
修复 React Fragment 中缺少 key 属性的问题
在使用列表渲染时,每个 React Fragment 都需要添加 key 属性。
建议使用以下修复方案:
📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 101-101: Missing key property for this element in iterable.
The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.
(lint/correctness/useJsxKeyInIterable)
[error] 105-105: Missing key property for this element in iterable.
The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.
(lint/correctness/useJsxKeyInIterable)