Skip to content

Commit

Permalink
feat(ui5-dynamic-page-title): streamline snapped title handling on mo…
Browse files Browse the repository at this point in the history
…bile

Refactored the implementation to pass the "snappedTitleOnMobile" state
from parent to child. This change ensures proper state management,
addressing previous review comments.
  • Loading branch information
kgogov committed Sep 26, 2024
1 parent 5aaa5f6 commit 982ec0a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/fiori/src/DynamicPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class DynamicPage extends UI5Element {
if (this.dynamicPageTitle) {
this.dynamicPageTitle.snapped = this._headerSnapped;
this.dynamicPageTitle.interactive = this.hasHeading;
this.dynamicPageTitle.hasSnappedTitleOnMobile = !!this.hasSnappedTitleOnMobile;
}
}

Expand Down
21 changes: 9 additions & 12 deletions packages/fiori/src/DynamicPageTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { isEnter, isSpace } from "@ui5/webcomponents-base/dist/Keys.js";
import type Toolbar from "@ui5/webcomponents/dist/Toolbar.js";
import type { ToolbarMinWidthChangeEventDetail } from "@ui5/webcomponents/dist/Toolbar.js";
import ToolbarItemOverflowBehavior from "@ui5/webcomponents/dist/types/ToolbarItemOverflowBehavior.js";
import { isDesktop, isPhone } from "@ui5/webcomponents-base/dist/Device.js";
import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import Icon from "@ui5/webcomponents/dist/Icon.js";
import Title from "@ui5/webcomponents/dist/Title.js";

Expand Down Expand Up @@ -113,6 +113,13 @@ class DynamicPageTitle extends UI5Element {
@property({ type: Number })
minActionsWidth?: number;

/**
* Indicates whether the title has snapped on mobile devices.
* @private
*/
@property({ type: Boolean })
hasSnappedTitleOnMobile = false;

/**
* Defines the content of the Heading of the Dynamic Page.
*
Expand Down Expand Up @@ -148,7 +155,7 @@ class DynamicPageTitle extends UI5Element {
* @public
* @since 2.3.0
*/
@slot({ type: Title })
@slot({ type: HTMLElement })
snappedTitleOnMobile!: Array<Title>;

/**
Expand Down Expand Up @@ -231,12 +238,6 @@ class DynamicPageTitle extends UI5Element {

onBeforeRendering() {
this.prepareLayoutActions();

if (this.hasSnappedTitleOnMobile) {
this.setAttribute("_snapped-title-on-mobile", "");
} else {
this.removeAttribute("_snapped-title-on-mobile");
}
}

get styles() {
Expand Down Expand Up @@ -269,10 +270,6 @@ class DynamicPageTitle extends UI5Element {
return this.interactive ? "0" : undefined;
}

get hasSnappedTitleOnMobile() {
return isPhone() && this.snapped && this.snappedTitleOnMobile.length;
}

get _headerExpanded() {
return !this.snapped;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fiori/src/themes/DynamicPageTitle.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
box-shadow: var(--sapContent_HeaderShadow);
}

:host([snapped][_snapped-title-on-mobile]) {
:host([has-snapped-title-on-mobile]) {
min-height: var(--_ui5_dynamic_page_snapped_title_on_mobile_min_height);
line-height: var(--_ui5_dynamic_page_snapped_title_on_mobile_line_height);
}
Expand Down

0 comments on commit 982ec0a

Please sign in to comment.