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

Allow HTML tooltips #883

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Allow tooltip to return undefined
 tooltip: >
    [[[
        var show_buttoncard_tooltips= states['var.show_buttoncard_tooltips'].state;
        if (show_buttoncard_tooltips != "True")
          return undefined;
In order to prevent tooltips from showing you can return undefined like above.
  • Loading branch information
engelchrisi committed Dec 25, 2024
commit 3d36b100727ffbe234fc578844219b7d23e6d1ab
24 changes: 2 additions & 22 deletions .vscode/bookmarks.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
{
"files": [
{
"path": "dist/button-card.js",
"bookmarks": [
{
"line": 3841,
"column": 12,
"label": ""
},
{
"line": 3843,
"column": 20,
"label": ""
},
{
"line": 3926,
"column": 26,
"label": ""
}
]
},
{
"path": "src/button-card.ts",
"bookmarks": [
Expand All @@ -29,12 +9,12 @@
"label": ""
},
{
"line": 1013,
"line": 1015,
"column": 40,
"label": ""
},
{
"line": 1103,
"line": 1105,
"column": 47,
"label": ""
}
Expand Down
6 changes: 4 additions & 2 deletions src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ class ButtonCard extends LitElement {
</style>
`
: html``;
let tooltipValue: string | undefined = undefined;
return html`
${extraStyles}
<div id="aspect-ratio" style=${styleMap(aspectRatio)}>
Expand Down Expand Up @@ -1008,10 +1009,11 @@ class ButtonCard extends LitElement {
</ha-card>
${this._getLock(lockStyle)}
</div>
${this._config?.tooltip
${this._config?.tooltip &&
(tooltipValue = this._getTemplateOrValue(this._stateObj, this._config.tooltip)) !== undefined
? html`
<span class="tooltiptext" style=${styleMap(tooltipStyleFromConfig)}>
${this._unsafeHTMLorNot(this._getTemplateOrValue(this._stateObj, this._config.tooltip))}
${this._unsafeHTMLorNot(tooltipValue)}
</span>
`
: ''}
Expand Down