Skip to content

Commit

Permalink
fix: keyframes can be declared in CSSObject (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadCcc committed Apr 20, 2022
1 parent 4638475 commit bf6cc41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/useStyleRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const parseStyle = (
if (
typeof value === 'object' &&
value &&
!(value as Keyframes)._keyframe &&
(key !== 'animationName' || !(value as Keyframes)._keyframe) &&
!isCompoundCSSProperty(value)
) {
let subInjectHash = false;
Expand Down
23 changes: 23 additions & 0 deletions tests/animation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,28 @@ describe('animation', () => {
`@keyframes ${testHashId}-anim{to{transform:rotate(360deg);}}.${testHashId}.demo{animation-name:${testHashId}-anim;}`,
);
});

it('could be declared in CSSObject', () => {
let testHashId = '';

const Demo = () => {
const [token, hashId] = useCacheToken(theme, [baseToken]);
testHashId = hashId;
useStyleRegister(
{ theme, token, path: ['keyframes-hashed'], hashId },
() => [{ '.demo': { animationName: animation, test: animation } }],
);
return <div />;
};
render(<Demo />);

const styles = Array.from(document.head.querySelectorAll('style'));
expect(styles).toHaveLength(1);

const style = styles[0];
expect(style.innerHTML).toEqual(
`.${testHashId}.demo{animation-name:${testHashId}-anim;}@keyframes ${testHashId}-anim{to{transform:rotate(360deg);}}`,
);
});
});
});

0 comments on commit bf6cc41

Please sign in to comment.