Placement of the action button in notifications

Currently, I am working on creating a Vue/Bootstrap notifications component with action buttons.

However, no matter what I try, the buttons end up being a part of the notification body itself. See my current result here:
https://i.sstatic.net/pLqn83fg.png

What I actually want is to have the buttons displayed at the bottom like so:
https://i.sstatic.net/igQi3fj8.png

The goal is for the button(s) to occupy the entire width.

This is the code snippet for the current version of the Vue component:

<template>
  <ul class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1050;">
    <li v-for="(notification, index) in notifications" :key="index"
      class="toast show align-items-center text-white border-0 mb-2 auto-dissmis" @click="removeNotification(index)">
      <div class="toast-indicator" :class="'bg-' + notification.type"></div>
      <div class="toast-body" v-html="notification.message"></div>
      <div class="toast-footer">
        <button class="btn btn-outline-primary d-block" @click="action.handler(action, $event)"
          v-for="action in notification.actions">
          {{ action.title }}
        </button>
      </div>
    </li>
  </ul>
</template>

... rest of the Vue component code snippet remains unchanged ...

Answer №1

Successfully found the solution. To implement this, start by creating two div's within the li element - one for the toast itself and another for the buttons:

<template>

  <!--
  <ul class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1050;">

    <li class="toast show align-items-center text-white border-0 mb-2 auto-dissmis">
      <div class="toast-indicator"></div>
      <div class="toast-body">
        Hello World Message

      </div>
      <div class="btn-group d-flex" role="group" aria-label="Basic example">
        <button type="button" class="btn btn-outline-primary flex-fill">Left</button>
        <button type="button" class="btn btn-outline-primary flex-fill">Middle</button>
        <button type="button" class="btn btn-outline-primary flex-fill">Right</button>
      </div>
    </li>

  </ul>
  -->


  <ul class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1050;">

    <li v-for="(notification, index) in notifications" :key="index" @click="removeNotification(index)" class="mb-2 ">
      <div class="toast align-items-center text-white border-0"
        :class="{ 'toast-no-bottom-border-radius': notification.actions.length > 0 }">
        <div class="toast-indicator" :class="'bg-' + notification.type"></div>
        <div class="toast-body" v-html="notification.message"></div>
      </div>
      <div class="btn-group d-flex">
        <button type="button" class="btn btn-outline-primary flex-fill" v-for="(action, index) in notification.actions"
          :key="index" @click="action.handler(action, $event)">
          {{ action.title }}
        </button>
      </div>
    </li>

  </ul>
</template>

<script>
export default {
  name: "Notification",
  data() {
    return {
      notifications: [],
    };
  },
  methods: {
    addNotification(message, opts) {

      opts = Object.assign({
        message,
        type: "primary",
        actions: []
      }, opts);

      this.notifications.push(opts);

      setTimeout(() => {
        if (this.notifications.length > 0) {
          //this.notifications.shift();
        }
      }, 2400);

    },
    removeNotification(index) {
      this.notifications.splice(index, 1);
    },
  },
  mounted() {

    let handler = (self, event) => {

      if (event) {
        event.stopPropagation();
        event.preventDefault();
      }

      alert("Clicked", self, event);

    };

    this.addNotification(`Sample notification #1`, {
      actions: [{
        title: "Foo",
        handler,
      }, {
        title: "Bar",
        handler,
      }]
    });

    this.addNotification(`Sample notification #2`, {
      type: "success"
    });

    /*
    ["info", "primary", "success", "warning", "danger"].forEach((color, i) => {
      setTimeout(() => {
        this.addNotification(`Sample notification #${i}`, color);
      }, i * 1000);
    });
    */

  },
};
</script>

<style scoped>
.btn-group button:nth-child(1) {
  border-top-left-radius: 0;
}

.btn-group button:last-child {
  border-top-right-radius: 0;
}

.toast-container {
  width: 380px;
  list-style: none;
}

.toast {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  cursor: pointer;
  background-color: #343a40 !important
}

.toast-no-bottom-border-radius {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.toast-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 6px;
  height: 100%;
}

.toast-actions {
  margin: 0;
}

.btn-group button {
  pointer-events: auto;
}

li.auto-dissmis>div.toast>.toast-indicator {
  animation: progress 2.4s linear forwards;
}

@keyframes progress {
  0% {
    height: 100%;
  }

  100% {
    height: 0;
  }
}
</style>

https://i.sstatic.net/pBhUbQuf.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React element failing to appear on webpage

I'm having trouble loading the snippetInfo.js file in the HTML, and I can't seem to figure out why. I've searched online extensively for solutions, but none of them have worked for me. Whenever I try adding type='text/javascript' t ...

iOS 7 users experiencing webpage crashes

UPDATE: Success! After some trial and error, I discovered that iOS 7 is not compatible with vh units. I switched to using JavaScript for detecting the browser height, and now my website works flawlessly on iOS 7. I recently created a website that function ...

What is the method for displaying a message in an invalid feedback?

I'm having trouble with displaying an error message in the invalid feedback section (confirm password) when the password does not match the confirm password using jQuery. However, even after deleting a single character from the password, the error mes ...

What is the best way to retain an edited value within the same index without moving it to a different

One issue I encounter is when attempting to save an edited value on the same index, but the value cannot be saved because the editing mode has not been closed. This pertains to a TypeScript File where I need to save the edited value in a selected Command ...

Discover how to find and retrieve an entire string by matching a single string with JavaScript

Looking for a solution to search a single string and return the entire string. $(document).ready(function() { $('button').click(function () { var search = $('#input').val(); var str = $('#file').html(); var output=str.match ...

Highlighted Navigation Options

When visiting , take note of the top navigation bar. The background color on this page is white, but as you navigate to other pages, the tab changes to a different color. How can you modify this behavior and change the class? Is PHP or jQuery necessary f ...

Ajax encounters a 400 Bad Request error upon attempting to submit a form

I am having trouble sending form data to my server using AJAX. Despite writing the following code, I keep receiving a 400 Bad error. Can anyone assist me with this? $(document).ready(function(){ // click on button submit $("#submit").on('clic ...

Having Trouble with jQuery toggleClass

I'm currently working on a project where I have implemented a button that displays a menu when clicked. I am attempting to change the color of the button when it is active, however, the toggleClass function is not behaving as expected. Below is the co ...

Switching the display of a Bootstrap navigation dropdown

After building a Bootstrap menu with a lightbox effect that overlays the page content when expanded, I encountered some issues. I attempted to use JavaScript functions to hide and display the lightbox_container element when toggling the nav. However, addi ...

Error: 'require is not defined' pops up while trying to import into App.js for a React App built with CDN links

My latest project involves a React App that showcases an h1 tag saying "Hello World" on the browser. Rather than utilizing npm, I have opted for CDN links to set up the application. The structure of the App consists of three key files: An index.html file ...

Ways to set a random value to a data attribute from a specified array while using v-for in Vue.js?

In my main Vue instance, I have a data attribute that consists of an array containing 4 items: var app = new Vue({ el: '#app', efeitosAos: ['fade', 'flip-up', 'slide-up', 'zoom-in'] ...

Tips for enlarging text without affecting the neighboring elements through the use of flexbox

I am currently working on designing a layout where clicking on "See More" will expand the text within one container while keeping the surrounding containers in place. There are three containers, each containing two wrappers - a top wrapper with the title ...

Create a stylish grid layout with perfectly centered content using CSS

I am in the process of developing a layout for print material on sticker labels. To achieve this, I have created a div element and applied the display:grid; property to customize the space allocation. My goal is to make item1, item2, and item3 overlap eac ...

Having difficulty setting a value for a tooltip with replaceWith() function

When using jQuery's .replaceWith() method to insert new DOM contents, I noticed that all content gets replaced except for the value of the title. Even though I tried different approaches, the tooltip only displays {{descriptions.title}} instead of the ...

Issue with reactivity in Laravel and Inertia.js using Vue3

Is it possible that the reactivity of Vue is being blocked by Inertia.js page components? Within my Page component, there is a single file component. I have a function that adds items to the ItemsManager.items object. When I run this function, the single ...

The Div title only appears once

I have a question about this code snippet: <div id="m1" class="drag"; title="CARS" style="position:absolute; left:0px; top:0px; width:32px; height:32px;"> <img src="http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/c ...

What is the correct way to utilize the `<svg>` element when loading external resources?

I have gone through numerous tutorials on how to add external SVGs to a webpage... such as this one: The code I am using looks like this: <svg> <use xlink:href="https://upload.wikimedia.org/wikipedia/commons/5/53/Skull_and_crossbones.svg">& ...

What are some ways to ensure that my css moving image element is responsive on smaller screens?

Currently, I am working on an image that has a downward motion upon page load. However, the issue arises when viewing it on smaller screens as it doesn't appear. How can this be resolved? Here is the HTML code: <img class="logo" src=&quo ...

Incorporating CSS into an HTML page created by a Python CGI script

Last week, I was handed a Python-based monitoring and notification tool to work on. My task is to develop a proof of concept dashboard using the data collected by this tool over the years. The catch is that I'm fairly new to Python and have never dabb ...

Bullet points may not appear when printing in IE8/9 unless you select the option to print background colors and images

I created a jsfiddle on http://jsfiddle.net/hxsy6/ The problem I'm facing is that when printing the page in IE7, the bullet points are printed with the actual bullet image. However, in IE8/9, they do not print. If I go to Print Preview -> click th ...