Skip to content

Commit 492778f

Browse files
author
Dennis Labordus
authored
feat(editors): Show label of Action Pane also as tool-tip (openscd#838)
* Show label of action-pane also as tooltip (through title) * Added test for title attribute.
1 parent 7af5b5c commit 492778f

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/action-pane.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ export class ActionPane extends LitElement {
7272
<nav><slot name="action"></slot></nav>`;
7373

7474
const headingLevel = Math.floor(Math.max(this.level, 1));
75+
// Sometimes a TemplateResult is passed in as Label, not a string. So only when it's a string show a title.
76+
const title = typeof this.label === 'string' ? this.label : '';
7577
switch (headingLevel) {
7678
case 1:
77-
return html`<h1>${content}</h1>`;
79+
return html`<h1 title="${title}">${content}</h1>`;
7880
case 2:
79-
return html`<h2>${content}</h2>`;
81+
return html`<h2 title="${title}">${content}</h2>`;
8082
case 3:
81-
return html`<h3>${content}</h3>`;
83+
return html`<h3 title="${title}">${content}</h3>`;
8284
default:
83-
return html`<h4>${content}</h4>`;
85+
return html`<h4 title="${title}">${content}</h4>`;
8486
}
8587
}
8688

test/unit/action-pane.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { ActionPane } from '../../src/action-pane.js';
66

77
describe('action-pane', () => {
88
let element: ActionPane;
9+
const label = 'test label';
910

1011
beforeEach(async () => {
1112
element = await fixture(
12-
html`<action-pane header="test header"></action-pane>`
13+
html`<action-pane header="test header" label="${label}"></action-pane>`
1314
);
1415
await element.updateComplete;
1516
});
@@ -79,6 +80,38 @@ describe('action-pane', () => {
7980
expect(element.shadowRoot?.querySelector('h4')).to.not.exist;
8081
});
8182

83+
it('renders the title on the <h1>', async () => {
84+
element.level = 1;
85+
await element.updateComplete;
86+
expect(
87+
element.shadowRoot?.querySelector('h1')!.getAttribute('title')
88+
).to.be.equals(label);
89+
});
90+
91+
it('renders the title on the <h2>', async () => {
92+
element.level = 2;
93+
await element.updateComplete;
94+
expect(
95+
element.shadowRoot?.querySelector('h2')!.getAttribute('title')
96+
).to.be.equals(label);
97+
});
98+
99+
it('renders the title on the <h3>', async () => {
100+
element.level = 3;
101+
await element.updateComplete;
102+
expect(
103+
element.shadowRoot?.querySelector('h3')!.getAttribute('title')
104+
).to.be.equals(label);
105+
});
106+
107+
it('renders the title on the <h4>', async () => {
108+
element.level = 4;
109+
await element.updateComplete;
110+
expect(
111+
element.shadowRoot?.querySelector('h4')!.getAttribute('title')
112+
).to.be.equals(label);
113+
});
114+
82115
it('does not set contrasted class property with odd level', async () => {
83116
element.level = 3;
84117
await element.updateComplete;

0 commit comments

Comments
 (0)