Files
WRNexusJS/packages/ui/components/badge.wrn
T
ClintchizandClaude Opus 5 5e65627305
Quality / quality (ubuntu-latest) (push) Failing after 13m39s
Quality / quality (windows-latest) (push) Canceled after 0s
fix(csr,ui): deliver component outputs to parent bindings
An output only reaches a parent @binding when the component calls
output.<name>(). Two separate faults meant most of the library never got
there, and both failed silently at each end.

HTML lowercases attribute names, so a parent's @sizeChange registered under
"sizechange" while the component emitted "sizeChange". The lookup missed, fell
through to a DOM dispatch, and the binding was never invoked. That made all 17
camelCase outputs undeliverable -- DataTable.pageChange and .rowClick,
Map.markerClick, ChatBubble.messageClick, LayoutSplitter.sizeChange and the
rest. invokeComponentOutput now falls back to a case-insensitive lookup, and a
csr test fails without it.

Separately, 18 components dispatched hand-built CustomEvents rather than
calling output.*. A bubbling event on the component's own root never reaches a
binding, because parent handlers live in a registry only the output proxy
reads. Card, Footer, Breadcrumb, Accordion, alert, Badge, AnnouncementBar,
AvatarGroup, ToggleCount and InputNumber now emit properly; Marquee, Map,
Timeline, List and SearchBox additionally declare the outputs they were
already firing. Dispatches on window are left alone -- that is how Toaster,
Modal and DataTable signal across component boundaries.

Verified in a browser both ways before and after: an AnnouncementBar
dispatching its own bubbling "dismiss" never reached a page-level @dismiss,
and reached it immediately once it called output.dismiss().

This corrects the audit, which called the LayoutSplitter failure "narrow and
unexplained" and read 32 dead outputs as 16 components needing a rebuild.
"Outputs work elsewhere" was an assumption; the components that worked
happened to use lowercase names and output.*. The dead-output ratchet drops
from 32 to 22, and a new test forbids the raw-CustomEvent pattern outright.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-09 01:40:39 +05:30

104 lines
3.3 KiB
Plaintext

component Badge {
outputs {
dismiss(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
}
props {
label: string = "Badge"
size: string = "md"
color: string = "primary"
variant: string = "solid"
shape: string = "pill"
class: string = ""
icon: string = ""
iconPosition: string = "start"
dot: boolean = false
dotOnly: boolean = false
dotLabel: string = "Status"
animated: boolean = false
avatarSrc: string = ""
avatarAlt: string = ""
dismissible: boolean = false
dismissLabel: string = "Remove badge"
truncate: boolean = false
maxWidth: string = "12rem"
anchorLabel: string = ""
anchorIcon: string = ""
placement: string = "inline"
anchorLabelText: string = "Badge anchor"
}
state visible: boolean = true
functions {
// output.dismiss reaches a parent @dismiss binding; a raw dispatchEvent on
// the root does not. The runtime registers parent handlers in a registry
// that only the output proxy consults, so the CustomEvent this used to
// build bubbled past every binding and was never seen by anyone.
client function dismissBadge() {
visible = false
output.dismiss({ component: "Badge", label: label })
}
}
view {
<span
{...attrs}
class="wire-next wire-next--badge-root {anchorLabel || anchorIcon ? 'wire-next--badge-anchored' : ''} {class}"
data-wrn-badge
data-placement="{placement}"
data-show="visible"
aria-hidden="{visible ? 'false' : 'true'}"
>
{#if anchorLabel || anchorIcon}
<button type="button" class="wire-next__badge-anchor" aria-label="{anchorLabelText}">
{#if anchorIcon}<span class="{anchorIcon}" aria-hidden="true"></span>{/if}
{#if anchorLabel}<span>{anchorLabel}</span>{/if}
</button>
{/if}
<span
class="wire-next__badge"
data-size="{size}"
data-color="{color}"
data-variant="{variant}"
data-shape="{shape}"
data-animated="{animated ? 'true' : 'false'}"
style="--wire-badge-max-width:{maxWidth}"
role="{dotOnly ? 'status' : ''}"
aria-label="{dotOnly ? dotLabel : ''}"
>
{#if animated}
<span class="wire-next__badge-ping" aria-hidden="true"></span>
{/if}
{#if avatarSrc}
<img class="wire-next__badge-avatar" src="{avatarSrc}" alt="{avatarAlt}" loading="lazy" />
{/if}
{#if dot || dotOnly}
<span class="wire-next__badge-dot" aria-hidden="true"></span>
{/if}
{#if icon && iconPosition === "start"}
<span class="wire-next__badge-icon {icon}" aria-hidden="true"></span>
{/if}
{#if !dotOnly}
<span class="wire-next__badge-label {truncate ? 'wire-next__badge-label--truncate' : ''}">
{label}
</span>
{/if}
{#if icon && iconPosition === "end"}
<span class="wire-next__badge-icon {icon}" aria-hidden="true"></span>
{/if}
{#if dismissible}
<button type="button" class="wire-next__badge-dismiss" aria-label="{dismissLabel}" @click="dismissBadge(event)">
<span class="icon-[lucide--x]" aria-hidden="true"></span>
</button>
{/if}
</span>
</span>
}
}