mirror of https://github.com/ElemeFE/element
Notification: add showClose option (#6402)
* Adding showClose option on Notification * Update notification.mdpull/7228/head
parent
a35ab0bb03
commit
209c4f86af
|
@ -95,6 +95,14 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
open13() {
|
||||||
|
this.$notify.success({
|
||||||
|
title: 'Info',
|
||||||
|
message: 'This is a message without close button',
|
||||||
|
showClose: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
console.log('Notification is closed');
|
console.log('Notification is closed');
|
||||||
}
|
}
|
||||||
|
@ -343,6 +351,36 @@ Customize Notification's offset from the edge of the screen.
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Hide Close button
|
||||||
|
|
||||||
|
It is possible to hide the close button
|
||||||
|
|
||||||
|
::: demo Set the `showClose` attribute to `false` so the notification cannot be closed by the user.
|
||||||
|
```html
|
||||||
|
<template>
|
||||||
|
<el-button
|
||||||
|
plain
|
||||||
|
@click="open13">
|
||||||
|
Hide close button
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
open13() {
|
||||||
|
this.$notify.success({
|
||||||
|
title: 'Info',
|
||||||
|
message: 'This is a message without close button',
|
||||||
|
showClose: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content.
|
Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content.
|
||||||
:::
|
:::
|
||||||
|
@ -371,6 +409,7 @@ In this case you should call `Notification(options)`. We have also registered me
|
||||||
| iconClass | custom icon's class. It will be overridden by `type` | string | — | — |
|
| iconClass | custom icon's class. It will be overridden by `type` | string | — | — |
|
||||||
| customClass | custom class name for Notification | string | — | — |
|
| customClass | custom class name for Notification | string | — | — |
|
||||||
| duration | duration before close. It will not automatically close if set 0 | number | — | 4500 |
|
| duration | duration before close. It will not automatically close if set 0 | number | — | 4500 |
|
||||||
|
| showClose | whether to show a close button | boolean | — | true |
|
||||||
| onClose | callback function when closed | function | — | — |
|
| onClose | callback function when closed | function | — | — |
|
||||||
| onClick | callback function when notification clicked | function | — | — |
|
| onClick | callback function when notification clicked | function | — | — |
|
||||||
| offset | offset from the top edge of the screen. Every Notification instance of the same moment should have the same offset | number | — | 0 |
|
| offset | offset from the top edge of the screen. Every Notification instance of the same moment should have the same offset | number | — | 0 |
|
||||||
|
|
|
@ -20,7 +20,10 @@
|
||||||
<p v-else v-html="message"></p>
|
<p v-else v-html="message"></p>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
<div class="el-notification__closeBtn el-icon-close" @click.stop="close"></div>
|
<div
|
||||||
|
class="el-notification__closeBtn el-icon-close"
|
||||||
|
v-if="showClose"
|
||||||
|
@click.stop="close"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -42,6 +45,7 @@
|
||||||
message: '',
|
message: '',
|
||||||
duration: 4500,
|
duration: 4500,
|
||||||
type: '',
|
type: '',
|
||||||
|
showClose: true,
|
||||||
customClass: '',
|
customClass: '',
|
||||||
iconClass: '',
|
iconClass: '',
|
||||||
onClose: null,
|
onClose: null,
|
||||||
|
|
|
@ -107,4 +107,15 @@ describe('Notification', () => {
|
||||||
}, 700);
|
}, 700);
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('no close button', done => {
|
||||||
|
Notification({
|
||||||
|
message: 'Hello',
|
||||||
|
showClose: false
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(document.querySelector('.el-notification__closeBtn')).to.not.exist;
|
||||||
|
done();
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue