Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spinner): fix spinner animation, prevent spinner resize in flex c… #1787

Merged
merged 1 commit into from
Dec 13, 2023
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
12 changes: 10 additions & 2 deletions src/components/spinner/spinner.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

// Note on flex:none on the :host
// Resizing a spinner element using anything but font-size will break the animation
// mostly because the animation uses em units. Therefore, if a spinner is used in a flex container,
// without flex:none applied, the spinner can grow/shrink and break the animation
// flex:none hopes to prevent this by always having the spinner sized according to its actual dimensions


export default css`
${componentStyles}

Expand All @@ -13,6 +20,7 @@ export default css`
display: inline-flex;
width: 1em;
height: 1em;
flex: none;
}

.spinner {
Expand Down Expand Up @@ -46,7 +54,7 @@ export default css`
@keyframes spin {
0% {
transform: rotate(0deg);
stroke-dasharray: 0.01em, 2.75em;
stroke-dasharray: 0.05em, 3em;
}

50% {
Expand All @@ -56,7 +64,7 @@ export default css`

100% {
transform: rotate(1080deg);
stroke-dasharray: 0.01em, 2.75em;
stroke-dasharray: 0.05em, 3em;
}
}
`;
7 changes: 7 additions & 0 deletions src/components/spinner/spinner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ describe('<sl-spinner>', () => {
//
expect(getComputedStyle(indicator).transform).to.equal('matrix(1, 0, 0, 1, 0, 0)');
});

it('should have flex:none to prevent flex re-sizing', async () => {
const spinner = await fixture<SlSpinner>(html` <sl-spinner></sl-spinner> `);

// 0 0 auto is a comiled value for `none`
expect(getComputedStyle(spinner).flex).to.equal('0 0 auto');
});
});
});
Loading