Skip to content

Commit

Permalink
Remove title attribute from Chips
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjhanson committed Feb 29, 2024
1 parent d17d1a1 commit db9dce0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ public static function chipHtml(Chippable $component, array $config = []): strin
$attributes = ArrayHelper::merge([
'id' => $config['id'],
'class' => ['chip', $config['size']],
'title' => $label,
'style' => array_filter([
'--custom-bg-color' => $color?->cssVar(50),
'--custom-text-color' => $color?->cssVar(900),
Expand Down Expand Up @@ -586,17 +585,9 @@ public static function elementChipHtml(ElementInterface $element, array $config
'sortable' => false,
];

$title = implode('', array_map(fn(string $segment) => "$segment", $element->getUiLabelPath())) .
$element->getUiLabel();

if (Craft::$app->getIsMultiSite()) {
$title .= sprintf(' - %s', Craft::t('site', $element->getSite()->getName()));
}

$config['attributes'] = ArrayHelper::merge(
self::baseElementAttributes($element, $config),
[
'title' => $title,
'data' => array_filter([
'settings' => $config['autoReload'] ? [
'context' => $config['context'],
Expand Down
27 changes: 24 additions & 3 deletions src/web/assets/cp/src/js/CraftElementLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class CraftElementLabel extends HTMLElement {
}

this.update();

// Update again when the document is ready.
// At the moment, this is necessary for this functionality within a dashboard
// widget. In that case, this component is rendered too early.
$(() => {
this.update();
});
}

update() {
Expand All @@ -50,12 +57,26 @@ class CraftElementLabel extends HTMLElement {

// If not, create one
if (!this.tooltip) {
this.tooltip = document.createElement('craft-tooltip');
this.tooltip.innerText = this.innerText;
this.labelLink.appendChild(this.tooltip);
this.createTooltip();
}
}

createTooltip() {
this.tooltip = document.createElement('craft-tooltip');
this.tooltip.innerText = this.innerText;

// If there's a context label, make it a little nicer
const contextLabel = this.querySelector('.context-label');
if (contextLabel) {
this.tooltip.innerText = this.tooltip.innerText.replace(
contextLabel.innerText,
` (${contextLabel.innerText})`
);
}

this.labelLink.appendChild(this.tooltip);
}

disconnectedCallback() {
this.tooltip?.remove();
this.$tabs.data('tabs')?.off('selectTab');
Expand Down

0 comments on commit db9dce0

Please sign in to comment.