Skip to content

Instantly share code, notes, and snippets.

@TatuLund
Created December 27, 2023 11:25
Show Gist options
  • Select an option

  • Save TatuLund/a5e90546696cfd081f2aefafdfbaece2 to your computer and use it in GitHub Desktop.

Select an option

Save TatuLund/a5e90546696cfd081f2aefafdfbaece2 to your computer and use it in GitHub Desktop.
There is no API in Vaadin 24 yet for setting overlay classname of the tooltip. You can use the following JavaScript utility function with Vaadin 24.2.0 and nwer.
public class TooltipUtils {
public static void setTooltipClassName(Component comp, String className) {
comp.getElement().executeJs(
"""
if ($0.getElementsByTagName('vaadin-tooltip').length == 1) {
$0.getElementsByTagName('vaadin-tooltip')[0]._overlayElement.setAttribute('class',$1);
} else {
const tooltips = document.getElementsByTagName('vaadin-tooltip');
for (let i=0; i<tooltips.length; i++ ) {
const tooltip = tooltips[i];
if (tooltip.children[0].id === $0.getAttribute('aria-describedBy')) {
tooltip._overlayElement.setAttribute('class',$1)
}
}
}
""", comp.getElement(), className);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment