Skip to content
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

Dynamically changing text to null/undefined does not remove/disable tooltip display #3

Open
jadrake75 opened this issue Jan 3, 2025 · 0 comments

Comments

@jadrake75
Copy link

So I have buttons/controls that for example should only show a tooltip if enabled (not disabled). To do this I am setting the tooltip based on a state variable. Here is an example from my paging component

<button
      @click="$emit('last')"
      :disabled="lastPage"
      ref="last"
      v-tooltip:top="lastPage ? undefined : t('paging.last')"
    >
      <span class="sw-icon-to-end disabled:opacity-50"></span>
    </button>

so if the state of the component is the lastPage it sets the tooltip to undefined. What is interesting is in this case for the first/last actions these are undefined initially and sure enough the early return on the

if (binding.value === null || binding.value === undefined)
    return;

Seems to skip building it, and then once they are enabled and I set tooltip text they will display text. I also verified that if I change the text this works fine.

So I think the issue is if the binding.value changes to be undefined you need to remove the class for 'vue-tooltip' and only add it if it gets by this point in the processing.... ie something like

const updateTooltip = (el: HTMLElement, binding: { value: string; modifiers: { [x: string]: boolean; }; arg?: string; }) => {
  const className = 'vue-tooltip';
  if (binding.value === null || binding.value === undefined) {
    el.classList.remove(className)
    return;
  }
  el.classList.add(className);
  el.dataset.tooltip = binding.value;
  el.classList.toggle(`${className}__${getStyleClass(binding.modifiers)}`, true);
  el.classList.toggle(`${className}__${binding.arg || 'bottom'}`, true);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant