Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-card): add loadingIndicator slot #9532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/main/src/BusyIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class BusyIndicator extends UI5Element {
return;
}

e.stopImmediatePropagation();
// e.stopImmediatePropagation();

// move the focus to the last element in this DOM and let TAB continue to the next focusable element
if (isTabNext(e)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/main/src/Card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
class="{{classes.root}}"
role="region"
aria-label="{{_getAriaLabel}}"
part="root">
part="root"
@keydown="{{_handleKeydown}}"
@focusin="{{_redirectFocus}}">
<slot name="loadingIndicator"></slot>
{{#if _hasHeader}}
<div class="ui5-card-header-root">
<slot name="header"></slot>
Expand All @@ -11,4 +14,5 @@
<div role="group" aria-label="{{_ariaCardContentLabel}}" part="content">
<slot></slot>
</div>
<span data-ui5-focus-redirect tabindex="0" ></span>
</div>
31 changes: 31 additions & 0 deletions packages/main/src/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { isTabNext } from "@ui5/webcomponents-base/dist/Keys.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
import CardTemplate from "./generated/templates/CardTemplate.lit.js";
import Icon from "./Icon.js";
Expand All @@ -13,6 +14,7 @@ import {
ARIA_LABEL_CARD_CONTENT,
} from "./generated/i18n/i18n-defaults.js";
import type CardHeader from "./CardHeader.js";
import type BusyIndicator from "./BusyIndicator.js";

// Styles
import cardCss from "./generated/themes/Card.css.js";
Expand Down Expand Up @@ -85,6 +87,9 @@ class Card extends UI5Element {
@slot({ type: HTMLElement, invalidateOnChildChange: true })
header!: Array<CardHeader>;

@slot()
loadingIndicator!: Array<BusyIndicator>;

static i18nBundle: I18nBundle;

get classes() {
Expand Down Expand Up @@ -114,6 +119,32 @@ class Card extends UI5Element {
static async onDefine() {
Card.i18nBundle = await getI18nBundle("@ui5/webcomponents");
}

_redirectFocus(e: FocusEvent) {
if (!this._isLoading) {
return;
}

if (!this.contains(e.relatedTarget as Node)) {
e.preventDefault();
this.loadingIndicator[0].focus();
}
}

_handleKeydown(e: KeyboardEvent) {
if (!this._isLoading) {
return;
}

// move the focus to the last element in this DOM and let TAB continue to the next focusable element
if (isTabNext(e)) {
this.shadowRoot!.querySelector<HTMLElement>("[data-ui5-focus-redirect]")!.focus();
}
}

get _isLoading() {
return this.loadingIndicator[0]?.active;
}
}

Card.define();
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/themes/BusyIndicator.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
border-radius: inherit;
}

:host(:not(:empty)) .ui5-busy-indicator-busy-area {
:host(:not(:empty)) .ui5-busy-indicator-busy-area,
:host-context([slot="loadingIndicator"]) .ui5-busy-indicator-busy-area {
background-color: var(--_ui5_busy_indicator_block_layer);
}

Expand Down
10 changes: 10 additions & 0 deletions packages/main/src/themes/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}

.ui5-card-root {
position: relative;
width: 100%;
height: 100%;
color: var(--sapGroup_TitleTextColor);
Expand All @@ -19,6 +20,15 @@
box-sizing: border-box;
}

::slotted([slot="loadingIndicator"]) {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: var(--_ui5_card_border-radius);
}

.ui5-card-root.ui5-card--interactive:hover {
box-shadow: var(--_ui5_card_hover_box_shadow);
}
Expand Down
1 change: 1 addition & 0 deletions packages/main/test/pages/Card.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<body class="card1auto">
<ui5-card id="card" class="myCard">
<ui5-busy-indicator active slot="loadingIndicator"></ui5-busy-indicator>
<ui5-card-header
id="cardHeader"
slot="header"
Expand Down
Loading