mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Toast): add message slot (#11018)
This commit is contained in:
parent
98642589ee
commit
43ff890d79
@ -71,7 +71,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
emits: ['update:show'],
|
emits: ['update:show'],
|
||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit, slots }) {
|
||||||
let timer: NodeJS.Timeout;
|
let timer: NodeJS.Timeout;
|
||||||
let clickable = false;
|
let clickable = false;
|
||||||
|
|
||||||
@ -118,6 +118,10 @@ export default defineComponent({
|
|||||||
const renderMessage = () => {
|
const renderMessage = () => {
|
||||||
const { type, message } = props;
|
const { type, message } = props;
|
||||||
|
|
||||||
|
if (slots.message) {
|
||||||
|
return <div class={bem('text')}>{slots.message()}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
if (isDef(message) && message !== '') {
|
if (isDef(message) && message !== '') {
|
||||||
return type === 'html' ? (
|
return type === 'html' ? (
|
||||||
<div key={0} class={bem('text')} innerHTML={String(message)} />
|
<div key={0} class={bem('text')} innerHTML={String(message)} />
|
||||||
|
@ -12,3 +12,17 @@ exports[`create a forbidClick toast 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</transition-stub>
|
</transition-stub>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`should render message slot correctly 1`] = `
|
||||||
|
<transition-stub>
|
||||||
|
<div role="dialog"
|
||||||
|
tabindex="0"
|
||||||
|
class="van-popup van-popup--center van-toast van-toast--middle van-toast--text"
|
||||||
|
style="z-index: 2007;"
|
||||||
|
>
|
||||||
|
<div class="van-toast__text">
|
||||||
|
Custom Message
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</transition-stub>
|
||||||
|
`;
|
||||||
|
@ -88,3 +88,17 @@ test('should change loading icon size when using icon-size prop', async () => {
|
|||||||
expect(wrapper.find('.van-loading__spinner').style.width).toEqual('10px');
|
expect(wrapper.find('.van-loading__spinner').style.width).toEqual('10px');
|
||||||
expect(wrapper.find('.van-loading__spinner').style.height).toEqual('10px');
|
expect(wrapper.find('.van-loading__spinner').style.height).toEqual('10px');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render message slot correctly', async () => {
|
||||||
|
const wrapper = mount(Toast, {
|
||||||
|
props: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
message: () => 'Custom Message',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user