Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/packages/fixednav/fixednav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@
.nut-fixednav-list-text {
font-size: 10px;
}

.b {
position: absolute;
right: 0;
top: 1px;
height: 14px;
line-height: 14px;
font-size: 10px;
padding: 0 3px;
color: white;
background: $color-primary;
border-radius: 7px;
text-align: center;
min-width: 12px;
}
}
}

Expand Down
38 changes: 25 additions & 13 deletions src/packages/fixednav/fixednav.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Overlay from '@/packages/overlay/index.taro'
import { useConfig } from '@/packages/configprovider/index.taro'
import { FixedNavProps } from './types.taro'
import { defaultOverlayProps } from '@/packages/overlay/overlay.taro'
import Badge from '@/packages/badge/index.taro'

const defaultProps: FixedNavProps = {
...defaultOverlayProps,
Expand Down Expand Up @@ -58,6 +59,23 @@ export const FixedNav: FunctionComponent<
className
)

const renderListItem = (item: any, index: number) => {
return (
<View
className={`${classPrefix}-list-item`}
onClick={(event) => onSelect(item, event as any)}
key={item.id || index}
>
{React.isValidElement(item.icon) ? (
item.icon
) : (
<img src={item.icon} alt="" />
)}
<View className={`${classPrefix}-list-text`}>{item.text}</View>
</View>
)
}

return (
<View
className={classes}
Expand All @@ -78,21 +96,15 @@ export const FixedNav: FunctionComponent<
<View className={`${classPrefix}-list`}>
{list.map((item: any, index) => {
return (
<View
className={`${classPrefix}-list-item`}
onClick={(event) => onSelect(item, event as any)}
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)}</>
)}
<View className={`${classPrefix}-list-text`}>
{item.text}
</View>
{item.num && <View className="b">{item.num}</View>}
</View>
</>
)
Comment on lines +99 to 108
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

修复 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<>
{item.num ? (
<Badge value={item.num} top={8} right={6}>
{renderListItem(item, index)}
</Badge>
) : (
<img src={item.icon} alt="" />
<>{renderListItem(item, index)}</>
)}
<View className={`${classPrefix}-list-text`}>
{item.text}
</View>
{item.num && <View className="b">{item.num}</View>}
</View>
</>
)
return (
<React.Fragment key={item.id || index}>
{item.num ? (
<Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
{renderListItem(item, index)}
</Badge>
) : (
<React.Fragment key={`item-${item.id || index}`}>{renderListItem(item, index)}</React.Fragment>
)}
</React.Fragment>
)
🧰 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)

})}
</View>
Expand Down
36 changes: 25 additions & 11 deletions src/packages/fixednav/fixednav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Check warning on line 70 in src/packages/fixednav/fixednav.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/fixednav/fixednav.tsx#L70

Added line #L70 was not covered by tests
) : (
<img src={item.icon} alt="" />
)}
<div className={`${classPrefix}-list-text`}>{item.text}</div>
</div>
)
}

return (
<div
className={classes}
Expand All @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

修复 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<>
{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>
</>
return (
<React.Fragment key={item.id || index}>
{item.num ? (
<Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
{renderListItem(item, index)}
</Badge>
) : (
<React.Fragment key={`item-${item.id || index}`}>
{renderListItem(item, index)}
</React.Fragment>
)}
</React.Fragment>
)
🧰 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.
Check the React documentation.

(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.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

)
})}
</div>
Expand Down
Loading