Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Sep 5, 2024
1 parent d040aea commit 0d8efc7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-papayas-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/avatar": patch
---

Fix issues where avatar could throw when the fallback inner text changes.
4 changes: 1 addition & 3 deletions examples/next-ts/pages/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ export default function Page() {
const [state, send] = useMachine(avatar.machine({ id: useId() }))
const [src, setSrc] = useState(images[0])
const [showImage, setShowImage] = useState(true)
const [name, setName] = useState("PA")

const api = avatar.connect(state, send, normalizeProps)

return (
<>
<main className="avatar">
<div {...api.getRootProps()}>
<span {...api.getFallbackProps()}>{name}</span>
<span {...api.getFallbackProps()}>PA</span>
{showImage && <img alt="" referrerPolicy="no-referrer" src={src} {...api.getImageProps()} />}
</div>

<div className="controls">
<button onClick={() => setSrc(getRandomImage())}>Change Image</button>
<button onClick={() => setSrc(avatarData.broken)}>Broken Image</button>
<button onClick={() => setShowImage((c) => !c)}>Toggle Image</button>
<input type="text" value={name} onChange={(e) => setName(e.target.value)} />
</div>
</main>

Expand Down

0 comments on commit 0d8efc7

Please sign in to comment.