feat:dropdownButton children buttons level & className (#7777)

This commit is contained in:
yujinghan 2023-08-11 10:29:59 +08:00 committed by GitHub
parent 39797c4c4e
commit 24fa5db8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 4 deletions

View File

@ -10,6 +10,7 @@
* 7. defaultIsOpened
* 8. align
* 9. block & size
* 10. buttons level & className
*/
import React from 'react';
@ -396,3 +397,36 @@ test('Renderer:dropdown-button with block & size', async () => {
);
expect(container).toMatchSnapshot();
});
test('Renderer:dropdown-button buttons with className & level', async () => {
const {container} = render(
amisRender({
type: "dropdown-button",
level: "success",
label: "下拉菜单",
buttons: [
{
type: "button",
label: "按钮1",
level: "success",
className: "custom-button-class"
},
{
type: "button",
label: "按钮2"
}
]
})
);
const dropdownButton = document.querySelector('button.cxd-Button');
fireEvent.click(dropdownButton as HTMLDivElement);
expect(container.querySelectorAll('.cxd-DropDown-menu-root .cxd-DropDown-button')[0]!).toHaveClass(
'cxd-Button--success'
);
expect(container.querySelectorAll('.cxd-DropDown-menu-root .cxd-DropDown-button')[0]!).toHaveClass(
'custom-button-class'
);
});

View File

@ -279,15 +279,25 @@ export default class DropDownButton extends React.Component<
return (
<li
key={index}
className={cx('DropDown-button', {
['is-disabled']: isDisabled(button, data)
})}
className={cx(
'DropDown-button',
{
['is-disabled']: isDisabled(button, data)
},
typeof button.level === 'undefined'
? ''
: button.level
? `Button--${button.level}`
: '',
button.className
)}
>
{render(
`button/${index}`,
{
type: 'button',
...(button as any)
...(button as any),
className: ''
},
{
isMenuItem: true,