Skip to content

Commit 710053b

Browse files
authored
feat(ui5-panel): enable configuring the heading level (#1504)
**Background** Our native title used to be "h1", which is indeed wrong. In openui5 it is "h2" and it is not configurable. But, in the related issue the author wants to be able to change the title level in general. Although we provide the possibility of a custom header, the author is asking for this feature to make use of the fact that the the entire native header is clickable and focusable, which is not the case with the custom one. **Options** So, we either reject this and (1) hardcode it to "h2" as in openui5, (2) introduce a property as in this change, or (3) make another slot for the title, but then we will have the current "header" slot and "headerTitle" slot and it might be confusing. **In this change:** - [refactoring] Use div with role="heading" and "aria-level" attrs, instead of "h" tag to enable the configuration of the level. Reuse the existing TitleLevel enum ("H1" to "H6") and extract the number part, but AriaLevel type ("1" - "6") is also an option. - [FIX] sync the parameters in the latest visual design and change few variables - [FIX] title now truncates, previously it used to wrap. Fixes: #1495
1 parent 746f907 commit 710053b

File tree

8 files changed

+40
-9
lines changed

8 files changed

+40
-9
lines changed

packages/main/src/Panel.hbs

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
{{#if _hasHeader}}
3131
<slot name="header"></slot>
3232
{{else}}
33-
<div class="ui5-panel-header-content">
34-
<h1 class="ui5-panel-header-title">{{headerText}}</h1>
33+
<div
34+
role="heading"
35+
aria-level="{{headerAriaLevel}}"
36+
class="ui5-panel-header-title"
37+
>
38+
{{headerText}}
3539
</div>
3640
{{/if}}
3741
</div>

packages/main/src/Panel.js

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationM
88
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
99
import "@ui5/webcomponents-icons/dist/icons/navigation-right-arrow.js";
1010
import Button from "./Button.js";
11+
import TitleLevel from "./types/TitleLevel.js";
1112
import PanelAccessibleRole from "./types/PanelAccessibleRole.js";
1213
import PanelTemplate from "./generated/templates/PanelTemplate.lit.js";
1314

@@ -102,6 +103,20 @@ const metadata = {
102103
defaultValue: PanelAccessibleRole.Form,
103104
},
104105

106+
/**
107+
* Defines the "aria-level" of <code>ui5-panel</code> heading,
108+
* set by the <code>headerText</code>.
109+
* <br><br>
110+
* Available options are: <code>"H6"</code> to <code>"H1"</code>.
111+
* @type {TitleLevel}
112+
* @defaultvalue "H2"
113+
* @public
114+
*/
115+
headerLevel: {
116+
type: TitleLevel,
117+
defaultValue: TitleLevel.H2,
118+
},
119+
105120
/**
106121
* @private
107122
*/
@@ -347,6 +362,10 @@ class Panel extends UI5Element {
347362
};
348363
}
349364

365+
get headerAriaLevel() {
366+
return this.headerLevel.slice(1);
367+
}
368+
350369
get headerTabIndex() {
351370
return (this.header.length || this.fixed) ? "-1" : "0";
352371
}

packages/main/src/themes/Panel.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@
5454
transform: rotate(90deg);
5555
}
5656

57+
:host([fixed]) .ui5-panel-header-title {
58+
width: 100%;
59+
}
60+
5761
.ui5-panel-header-title {
58-
font-family: var(--sapFontFamily);
59-
font-size: var(--_ui5_panel_header_title_size);
62+
width: calc(100% - var(--_ui5_panel_button_root_width));
63+
overflow: hidden;
64+
text-overflow: ellipsis;
65+
white-space: nowrap;
66+
font-family: var(--sapFontHeaderFamily);
67+
font-size: var(--sapFontHeader5Size);
6068
font-weight: normal;
6169
color: var(--sapGroup_TitleTextColor);
6270
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
:root {
22
--_ui5_panel_focus_border: 1px dotted var(--sapContent_FocusColor);
33
--_ui5_panel_header_height: 3rem;
4-
--_ui5_panel_header_title_size: var(--sapMFontHeader4Size);
54
--_ui5_panel_button_root_width: 3rem;
65
}

packages/main/src/themes/sap_fiori_3/Panel-parameters.css

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
:root {
44
--_ui5_panel_header_height: 2.75rem;
5-
--_ui5_panel_header_title_size: var(--sapMFontHeader5Size);
65
--_ui5_panel_button_root_width: 2.75rem;
76
}

packages/main/src/themes/sap_fiori_3_dark/Panel-parameters.css

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
:root {
44
--_ui5_panel_header_height: 2.75rem;
5-
--_ui5_panel_header_title_size: var(--sapMFontHeader5Size);
65
--_ui5_panel_button_root_width: 2.75rem;
76
}

packages/main/test/pages/Panel.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
<br>
106106

107-
<ui5-panel id="panel-expandable" accessible-role="Complementary" header-text="Both expandable and expanded">
107+
<ui5-panel id="panel-expandable" accessible-role="Complementary" header-text="Both expandable and expanded" header-level="H4">
108108

109109

110110
<!-- Content -->
@@ -160,7 +160,7 @@
160160

161161
<br>
162162

163-
<ui5-panel id="panel1" collapsed header-text="Click to expand!">
163+
<ui5-panel id="panel1" collapsed header-text="Click to expand!" header-level="H3">
164164

165165
<!-- Content -->
166166
<ui5-title>This is a demo how to use the &quot;expand&quot; event.</ui5-title>

packages/main/test/specs/Panel.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe("Panel general interaction", () => {
101101

102102
it("tests whether aria attributes are set correctly with native header", () => {
103103
const header = browser.$("#panel1").shadow$(".ui5-panel-header");
104+
const title = browser.$("#panel1").shadow$(".ui5-panel-header-title");
104105
const button = browser.$("#panel1").shadow$(".ui5-panel-header-button");
105106

106107
assert.ok(!button.getAttribute("aria-expanded"), "aria-expanded shouldn't be set on the button");
@@ -109,6 +110,8 @@ describe("Panel general interaction", () => {
109110

110111
assert.ok(header.getAttribute("aria-expanded"), "aria-expanded should be set on the header");
111112
assert.ok(header.getAttribute("aria-controls"), "aria-controls should be set on the header");
113+
114+
assert.strictEqual(title.getAttribute("aria-level"), "3", "title aria-level is set to 3 correctly");
112115
});
113116

114117
it("tests whether aria attributes are set correctly in case of custom header", () => {

0 commit comments

Comments
 (0)