Skip to content
Open
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
22 changes: 22 additions & 0 deletions packages/main/cypress/specs/ExpandableText.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ describe("ExpandableText", () => {
.should("exist");
});

it("Scrolls toggle link into view on expansion", () => {
const text = "A".repeat(5000);
const maxCharacters = 5;

cy.mount(
<div style={{ height: "200px", overflow: "auto" }}>
<ExpandableText text={text} maxCharacters={maxCharacters}></ExpandableText>
</div>
);

cy.get("[ui5-expandable-text]").shadow().as("expTextShadow");
cy.get("@expTextShadow").find(".ui5-exp-text-toggle").as("toggle");

cy.get("@toggle")
.contains(EXPANDABLE_TEXT_SHOW_MORE.defaultText)
.realClick();

cy.get("@toggle")
.contains(EXPANDABLE_TEXT_SHOW_LESS.defaultText)
.should("be.visible");
});

it("ARIA attributes", () => {
const text = "This is a very long text that should be displayed";

Expand Down
14 changes: 14 additions & 0 deletions packages/main/src/ExpandableText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ExpandableText extends UI5Element {
@property({ type: Boolean })
_expanded = false;

_shouldScrollToToggle = false;

@i18n("@ui5/webcomponents")
static i18nBundle: I18nBundle;

Expand Down Expand Up @@ -166,8 +168,20 @@ class ExpandableText extends UI5Element {
}
}

onAfterRendering() {
if (this._shouldScrollToToggle) {
this._shouldScrollToToggle = false;
const toggleLink = this.shadowRoot?.querySelector<HTMLElement>("#toggle");
toggleLink?.scrollIntoView?.({ block: "nearest" });
}
}

_handleToggleClick() {
this._expanded = !this._expanded;

if (this._expanded && !this._usePopover) {
this._shouldScrollToToggle = true;
}
}

_handleCloseButtonClick(e: UI5CustomEvent<Button, "click">) {
Expand Down
Loading