Skip to content

Commit e99d7a4

Browse files
authored
fix(app): text-shimmer undefined length (anomalyco#16475)
1 parent f0beb38 commit e99d7a4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

packages/ui/src/components/text-shimmer.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
88
active?: boolean
99
offset?: number
1010
}) => {
11+
const text = createMemo(() => props.text ?? "")
1112
const active = createMemo(() => props.active ?? true)
1213
const offset = createMemo(() => props.offset ?? 0)
1314
const [run, setRun] = createSignal(active())
@@ -36,17 +37,14 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
3637
clearTimeout(timer)
3738
})
3839

39-
const shimmerSize = createMemo(() => {
40-
const len = Math.max(props.text.length, 1)
41-
return Math.max(300, Math.round(200 + 1400 / len))
42-
})
40+
const len = createMemo(() => Math.max(text().length, 1))
41+
const shimmerSize = createMemo(() => Math.max(300, Math.round(200 + 1400 / len())))
4342

4443
// duration = len × (size - 1) / velocity → uniform perceived sweep speed
4544
const VELOCITY = 0.01375 // ch per ms, ~10% faster than original 0.0125 baseline
4645
const shimmerDuration = createMemo(() => {
47-
const len = Math.max(props.text.length, 1)
4846
const s = shimmerSize() / 100
49-
return Math.max(1000, Math.min(2500, Math.round((len * (s - 1)) / VELOCITY)))
47+
return Math.max(1000, Math.min(2500, Math.round((len() * (s - 1)) / VELOCITY)))
5048
})
5149

5250
return (
@@ -55,7 +53,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
5553
data-component="text-shimmer"
5654
data-active={active() ? "true" : "false"}
5755
class={props.class}
58-
aria-label={props.text}
56+
aria-label={text()}
5957
style={{
6058
"--text-shimmer-swap": `${swap}ms`,
6159
"--text-shimmer-index": `${offset()}`,
@@ -65,10 +63,10 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
6563
>
6664
<span data-slot="text-shimmer-char">
6765
<span data-slot="text-shimmer-char-base" aria-hidden="true">
68-
{props.text}
66+
{text()}
6967
</span>
7068
<span data-slot="text-shimmer-char-shimmer" data-run={run() ? "true" : "false"} aria-hidden="true">
71-
{props.text}
69+
{text()}
7270
</span>
7371
</span>
7472
</Dynamic>

0 commit comments

Comments
 (0)