-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 3502-radio-buttons-selected-radio-button-…
…shouldcould-have-a-border-to-improve-ui
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
libs/extensions/angular/image-banner/src/image-banner-height.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Directive, ElementRef, inject, OnDestroy, OnInit, Renderer2 } from '@angular/core'; | ||
import { ResizeObserverService } from '@kirbydesign/designsystem/shared'; | ||
|
||
/** | ||
* @Description Temporary directive to ensure correct scroll position behavior on Safari. | ||
* | ||
* When navigating between stacked pages, scroll position is not correctly restored on Safari, | ||
* when the nested kirby-card element uses containment and the host element does not have an explicit height. | ||
*/ | ||
@Directive({ | ||
selector: `[kirbyImageBannerResize]`, | ||
}) | ||
export class ImageBannerHeightDirective implements OnInit, OnDestroy { | ||
private currentHeight: number = 0; | ||
private host = inject(ElementRef); | ||
private resizeObserverService = inject(ResizeObserverService); | ||
private renderer = inject(Renderer2); | ||
|
||
ngOnInit() { | ||
this.resizeObserverService.observe(this.host, (entry) => this.setCardHeightOnHost(entry)); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.resizeObserverService.unobserve(this.host); | ||
} | ||
|
||
private setCardHeightOnHost(entry: ResizeObserverEntry) { | ||
const hostElement = entry.target as HTMLElement; | ||
const card = hostElement.querySelector('kirby-card'); | ||
const cardHeight = card?.getBoundingClientRect().height; | ||
|
||
if (!hostElement || !cardHeight) return; | ||
if (cardHeight === this.currentHeight) return; | ||
|
||
this.currentHeight = cardHeight; | ||
this.renderer.setStyle(hostElement, 'min-height', `${cardHeight}px`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { ImageBannerComponent } from './image-banner.component'; | ||
export { ImageBannerHeightDirective } from './image-banner-height.directive'; |