Skip to content

Commit

Permalink
Merge pull request #2561 from dusk-network/fix-2557-handle-long-strin…
Browse files Browse the repository at this point in the history
…gs-in-data

Add maxlength to Badge and break long list items
  • Loading branch information
kieranhall authored Oct 3, 2024
2 parents 2de46c6 + 46ababf commit 4c73532
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions explorer/src/lib/components/list-item/ListItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
gap: 0.625rem;
align-items: center;
margin-bottom: 1.25rem;
line-break: anywhere;
}

.details-list__definition:last-of-type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/** @type {boolean} */
export let displayTooltips = false;
const BADGE_TEXT_MAX_LENGTH = 20;
</script>

<div class="transaction-type">
Expand All @@ -22,5 +24,5 @@
: mdiShieldOutline}
size="large"
/>
<Badge text={data.method} />
<Badge text={data.method} maxlength={BADGE_TEXT_MAX_LENGTH} />
</div>
10 changes: 10 additions & 0 deletions explorer/src/lib/dusk/components/__tests__/Badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ describe("Badge", () => {

expect(container.firstChild).toMatchSnapshot();
});

it("should only display a string 10 characters long", () => {
const props = {
...baseProps,
maxlength: 10,
text: "ABCDEFGHIJK",
};
const { container } = render(Badge, { ...props });
expect(container.firstChild?.textContent?.length).toBe(10);
});
});
5 changes: 4 additions & 1 deletion explorer/src/lib/dusk/components/badge/Badge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
/** @type {String | Undefined} */
export let className = undefined;
/** @type {number | Undefined} */
export let maxlength = undefined;
$: classes = makeClassName([
"dusk-badge",
`dusk-badge--variant-${variant}`,
className,
]);
</script>

<span {...$$restProps} class={classes}>{text}</span>
<span {...$$restProps} class={classes}>{text.substring(0, maxlength)}</span>

0 comments on commit 4c73532

Please sign in to comment.