Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/animated-className.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-spring/web': patch
---

fix: recognize `className` prop to `AnimatedComponent`s
10 changes: 10 additions & 0 deletions targets/web/src/animated.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe('animated component', () => {
mockRaf.step()
expect(wrapper.scrollTop).toBe(20)
})
it('accepts the className property', () => {
const className = spring('test')
const { getByTestId } = render(
<a.div className={className} data-testid="wrapper" />
)
expect(getByTestId('wrapper').className).toBe('test')
className.set('new')
mockRaf.step()
expect(getByTestId('wrapper').className).toBe('new')
})
it('accepts x/y/z as style keys equivalent to `translate3d`transform function', () => {
const { queryByTestId, rerender } = render(
<a.div style={{ x: 10 }} data-testid="wrapper" />
Expand Down
14 changes: 12 additions & 2 deletions targets/web/src/applyAnimatedValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ export function applyAnimatedValues(instance: Instance, props: Lookup) {
instance.nodeName === 'filter' ||
(instance.parentNode && instance.parentNode.nodeName === 'filter')

const { style, children, scrollTop, scrollLeft, viewBox, ...attributes } =
props!
const {
className,
style,
children,
scrollTop,
scrollLeft,
viewBox,
...attributes
} = props!

const values = Object.values(attributes)
const names = Object.keys(attributes).map(name =>
Expand Down Expand Up @@ -66,6 +73,9 @@ export function applyAnimatedValues(instance: Instance, props: Lookup) {
instance.setAttribute(name, values[i])
})

if (className !== void 0) {
instance.className = className
}
if (scrollTop !== void 0) {
instance.scrollTop = scrollTop
}
Expand Down