-
-
Notifications
You must be signed in to change notification settings - Fork 260
feat: Support custom rendering #792
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
base: master
Are you sure you want to change the base?
Changes from all commits
d45697e
b0829a4
e9f46a0
743803f
281afbb
9ad16df
a438a2e
8993061
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 |
---|---|---|
|
@@ -228,5 +228,40 @@ describe('MenuItem', () => { | |
|
||
expect(container.querySelector('li')).toMatchSnapshot(); | ||
}); | ||
|
||
it('should wrap originNode with custom render', () => { | ||
const { container } = render( | ||
<Menu | ||
itemRender={(originNode, { item }) => { | ||
if (item.type === 'item') { | ||
return ( | ||
<a href="https://ant.design" target="_blank" rel="noopener noreferrer"> | ||
{originNode} | ||
</a> | ||
); | ||
} | ||
return originNode; | ||
}} | ||
items={[ | ||
{ | ||
key: 'mail', | ||
type: 'item', | ||
label: 'Navigation One', | ||
}, | ||
{ | ||
key: 'app', | ||
label: 'Navigation Two', | ||
}, | ||
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. render 放 item 里意义不大,和直接写 label 没区别。用户期望的是可以在顶层统一配置 itemRender 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. <Menu itemRender={...} /> 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. done |
||
{ | ||
key: 'upload', | ||
label: 'Upload File', | ||
}, | ||
]} | ||
/>, | ||
); | ||
|
||
const link = container.querySelector('a'); | ||
expect(link).toHaveAttribute('href', 'https://ant.design'); | ||
}); | ||
}); | ||
}); |
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.
🛠️ Refactor suggestion
防止用户返回非
当前直接返回
mergedItemRender
的结果,若用户返回<div>
或 Fragment,将导致<ul>
子元素不是<li>
的非法结构,破坏语义与可访问性。建议:若返回值是
<li>
则直接使用;否则作为children
注入到现有<li>
中,并在开发环境给出告警。📝 Committable suggestion
🤖 Prompt for AI Agents