Search code examples
vue.jsbootstrap-4tooltipbootstrap-vue

Display Vue Bootstrap b-tooltip only if b-button is disabled


A b-button is conditionally disabled if the user is an admin. Right now, a b-tooltip displays when hovering over it and it is not disabled.

Is there a way to display the tooltip only if it is disabled?

I've tried adding the v-bind, a v-if, id:disabled, and multiple variations of those on the button and tooltip, to no avail.

<form ref="form" @click="handleDelete">
    <b-button v-bind:disabled="userRole !== 'admin'" id="tooltip-target-1" variant="danger">
        Admin Delete Agency
    </b-button>
    <b-tooltip target="tooltip-target-1" triggers="hover">
      You cannot delete an agency with children. Reassign child agencies to continue deletion.
    </b-tooltip>
</form>

Solution

  • I added a v-if on the tooltip and a span wrapping the button. Thanks @Romalex

        <form ref="form" @click="handleDelete">
          <span id="disabled-wrapper" class="d-inline-block" tabindex="0">
            <b-button v-bind:disabled="userRole !== 'admin'" style="pointer-events: none;" variant="danger">
              Admin Delete Agency
            </b-button>
          </span>
          <b-tooltip v-if="userRole !== 'admin'" target="disabled-wrapper" triggers="hover">
            You cannot delete an agency with children. Reassign child agencies to continue deletion.
          </b-tooltip>
        </form>