Skip to content

Commit 2711780

Browse files
author
Amber Febbraro
authored
Merge pull request #4033 from sparkdesignsystem/spinners-again
Spinners Fix Without TDP Fix
2 parents 2dc91b6 + 8dc0d59 commit 2711780

5 files changed

Lines changed: 65 additions & 6 deletions

File tree

html/components/button.stories.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ after Spark's JavaScript functions run.
4747
spinning. Defaults to an empty string.
4848
- \`data-sprk-spinner-variant="primary|secondary|dark"\` – The variant
4949
for the spinning icon.
50-
50+
- \`data-sprk-spinner="is-not-disabled"\` – This is identical to
51+
\`data-sprk-spinner="click"\` except the button will not be disabled when it
52+
is clicked. This should be used for buttons that submit a form.
5153
5254
###### Example Spinner Implementation
5355
\`\`\`

html/components/spinners.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ const setSpinning = (element, options) => {
3232
const spinningAriaLabel = options.ariaLabel || 'Loading';
3333
const ariaValueText = options.ariaValueText || 'Loading';
3434
const role = options.role || 'progressbar';
35+
const hasDoNotDisable = options.hasDoNotDisable || false;
3536

3637
el.classList.add('sprk-c-Button--has-spinner');
3738
el.setAttribute('aria-label', spinningAriaLabel);
3839
el.setAttribute('data-sprk-spinner-text', el.textContent);
39-
el.setAttribute('disabled', '');
4040
el.setAttribute('data-sprk-has-spinner', 'true');
4141
el.setAttribute('style', `width: ${width}px`);
4242

43+
// This flag should be used for submit buttons so that the
44+
// disabled attribute does not suppress the submit behavior.
45+
if (!hasDoNotDisable) {
46+
el.setAttribute('disabled', '');
47+
}
48+
4349
el.innerHTML = `
4450
<div
4551
class="${getSpinnerClasses(options)}"
@@ -60,8 +66,15 @@ const cancelSpinning = (element) => {
6066
};
6167

6268
const spinners = () => {
63-
getElements('[data-sprk-spinner="click"]', (spinnerContainer) => {
69+
getElements('[data-sprk-spinner]', (spinnerContainer) => {
70+
const spinnerType = spinnerContainer.getAttribute('data-sprk-spinner');
71+
6472
const options = {};
73+
74+
if (spinnerType === 'is-not-disabled') {
75+
options.hasDoNotDisable = true;
76+
}
77+
6578
options.size = spinnerContainer.getAttribute('data-sprk-spinner-size');
6679
// TODO: Deprecate lightness option in favor of variant - issue #1292
6780
options.lightness = spinnerContainer.getAttribute(

html/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sparkdesignsystem/spark",
3-
"version": "17.0.0",
3+
"version": "17.0.1",
44
"description": "Spark is the main package for the Spark Design System. This package contains the JavaScript and components that make up the basic interfaces for Quicken Loans Fintech products.",
55
"main": "es5/sparkExports.js",
66
"scripts": {

html/tests/spinners.tests.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('spinners init', () => {
1515
sinon.spy(document, 'querySelectorAll');
1616
spinners();
1717
expect(document.querySelectorAll.getCall(0).args[0]).toBe(
18-
'[data-sprk-spinner="click"]',
18+
'[data-sprk-spinner]',
1919
);
2020
});
2121
});
@@ -287,3 +287,47 @@ describe('cancelSpinning tests', () => {
287287
).toBe(false);
288288
});
289289
});
290+
291+
describe('spinners with is-not-disabled', () => {
292+
let spinnerContainer;
293+
294+
beforeEach(() => {
295+
spinnerContainer = document.createElement('button');
296+
spinnerContainer.setAttribute('data-sprk-spinner', 'is-not-disabled');
297+
spinnerContainer.textContent = 'Submit';
298+
299+
sinon.spy(spinnerContainer, 'addEventListener');
300+
sinon.spy(spinnerContainer, 'setAttribute');
301+
302+
document.body.append(spinnerContainer);
303+
spinners();
304+
});
305+
306+
afterEach(() => {
307+
document.body.innerHTML = '';
308+
spinnerContainer.addEventListener.restore();
309+
spinnerContainer.setAttribute.restore();
310+
});
311+
312+
it('should start spinning and not be disabled if its clicked', () => {
313+
spinnerContainer.click();
314+
315+
expect(
316+
spinnerContainer
317+
.querySelector('div')
318+
.classList.contains('sprk-c-Spinner--circle'),
319+
).toBe(true);
320+
321+
expect(spinnerContainer.hasAttribute('disabled')).toBe(false);
322+
});
323+
324+
it('should not start spinning if its already spinning', () => {
325+
spinnerContainer.setAttribute('data-sprk-has-spinner', 'true');
326+
327+
spinnerContainer.click();
328+
329+
expect(spinnerContainer.querySelector('div')).toBe(null);
330+
331+
expect(spinnerContainer.hasAttribute('disabled')).toBe(false);
332+
});
333+
});

0 commit comments

Comments
 (0)