Skip to content

feat(alert): Hide dismiss button for auto-dismissing alerts #791

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

Merged
merged 3 commits into from
Aug 10, 2017
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
4 changes: 3 additions & 1 deletion docs/components/alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Dismissible Alert!
</b-alert>

<b-alert :show="dismissCountDown" dismissible variant="warning" @dismiss-count-down="countDownChanged">
<b-alert :show="dismissCountDown" variant="warning" @dismiss-count-down="countDownChanged">
This alert will dismiss after {{dismissCountDown}} seconds...
</b-alert>

Expand Down Expand Up @@ -76,3 +76,5 @@ with the dismiss button.
#### Auto dismissing alerts:
To create a `<b-alert>` that dismisses automatically after a period of time, set
the `show` prop to the number of seconds you would like the `<b-alert>` to remain visible for.

Note that the dismiss button will not be shown for auto-dismissing alerts.
3 changes: 1 addition & 2 deletions examples/alert/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</b-alert>

<b-alert :show="dismissCountDown"
dismissible
variant="warning"
@dismiss-count-down="countDownChanged"
>
Expand All @@ -34,4 +33,4 @@
<b-btn @click="showDismissibleAlert=true" variant="info" class="m-1" ref="dismissible_alert_btn">
Show dismissible alert ({{showDismissibleAlert?'visible':'hidden'}})
</b-btn>
</div>
</div>
11 changes: 8 additions & 3 deletions lib/components/alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="close"
data-dismiss="alert"
:aria-label="dismissLabel"
v-if="dismissible"
v-if="localDismissible"
@click.stop.prevent="dismiss"
>
<span aria-hidden="true">&times;</span>
Expand All @@ -25,7 +25,8 @@
data() {
return {
countDownTimerId: null,
dismissed: false
dismissed: false,
localDismissible: this.dismissible
};
},
created() {
Expand All @@ -35,7 +36,7 @@
},
computed: {
classObject() {
return ['alert', this.alertVariant, this.dismissible ? 'alert-dismissible' : ''];
return ['alert', this.alertVariant, this.localDismissible ? 'alert-dismissible' : ''];
},
alertVariant() {
const variant = this.state || this.variant || 'info';
Expand Down Expand Up @@ -92,9 +93,13 @@

// No timer for boolean values
if (this.show === true || this.show === false || this.show === null || this.show === 0) {
this.localDismissible = this.dismissible;
return;
}

// Hide dismiss button for auto-dismissing
this.localDismissible = false;

let dismissCountDown = this.show;
this.$emit('dismiss-count-down', dismissCountDown);

Expand Down