Skip to content

Conversation

@ildar170975
Copy link
Contributor

@ildar170975 ildar170975 commented Oct 23, 2025

Breaking change

Proposed change

Display a description of a label in ha-tooltip:

image

Added in tables (automations, scripts, scenes, devices, entities, helpers) in 3 places:

image

Added in more-info:

image

Notes:

  1. Tooltips are only shown for ha-label used for LABELS, not in a "quick search", “+1” buttons etc.
  2. Tooltips are only shown if they are not empty - i.e. not just filled with whitespaces & line-breaks (of course this type of a content must be prevented in a “create/edit label” process, but I myself observed such a meaningless content of some of my labels, have no idea how it was allowed).
  3. uid() function is used to generate unique ids for target elements associated with tooltips.
  4. ha-label is a bit refactored (span is placed into a div) to make tooltips shown when hovering a whole ha-label element, not only a smaller span inside it.
  5. I observe an issue: a tooltip stops to appear if an associated element is moved on a screen (for instance, when a new label is placed before). The tooltip again starts to appear after F5. Probably related to an issue in webawesome which was recently fixed (Fix tooltip reconnection bug shoelace-style/webawesome#1603).

In a default dark theme it looks less visible - but this could be another PR:

image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@ildar170975 ildar170975 marked this pull request as ready for review October 24, 2025 00:40
@ildar170975
Copy link
Contributor Author

ildar170975 commented Oct 24, 2025

Note that in other PRs to avoid points in for a "slugify()" function is used.
But here there could be a possibility to display on a screen several ha-label elements for a SAME label.
So, the associated ids must be unique.

If there is a need to add a slugified label_id value into these ids (along with currently added UID) - tell me, will do.

@ildar170975
Copy link
Contributor Author

Resolved conflicts with #27594, a new look for ha-labels-picker:
image

@MindFreeze
Copy link
Member

I observe an issue: a tooltip stops to appear if an associated element is moved on a screen (for instance, when a new label is placed before). The tooltip again starts to appear after F5. Probably related to an issue in webawesome which was recently fixed (shoelace-style/webawesome#1603).

I've noticed this in dev recently, so it's not related to this PR

public description?: string;

protected render(): TemplateResult {
const elementId = "label-" + uid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can optimize this by adding private _uid = uid() so it doesn't generate it for every render

const color = label?.color
? computeCssColor(label.color)
: undefined;
const elementId = "label-" + uid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be optimized the same way

@click=${clickAction ? this._labelClicked : undefined}
@keydown=${clickAction ? this._labelClicked : undefined}
style=${color ? `--color: ${color}` : ""}
.description=${label.description ?? ""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute is defined as description?: string so the ?? "" is redundant. You can just pass the description as is. Same for all the other cases of description ?? ""

Comment on lines +19 to +21
.disabled=${this.description === undefined ||
this.description?.trim().replaceAll("\n", "").replaceAll("\r", "") ===
""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are slightly different in ha-labels-picker. They should be unified somehow.
Also no need to check === undefined and have a ? afterwards. One of these is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In more-info, for chips, a check for “undefined” turned to be not enough, had to add a check for “null”. Shall I add a check for “null” here as well? Or may be I shall find out a reason why it could be “null” in more-info.

@ildar170975 ildar170975 marked this pull request as draft October 29, 2025 10:52
@ildar170975
Copy link
Contributor Author

I've noticed this in dev recently, so it's not related to this PR

Thanks for comments!
Could this glitch be related to that mentioned shoelace-style/webawesome#1603 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants