Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
04f0fde
add naive / simple table sort
sknep Jan 19, 2021
3a45aad
lint fixes
sknep Jan 19, 2021
ddd9df8
Fix Number global
sknep Jan 19, 2021
3d6a667
Add borderless table & bordered active sort state
sknep Jan 19, 2021
d985b9d
Make button fill height of table cell
sknep Jan 19, 2021
ba86a80
Add locale-based sort
sknep Jan 19, 2021
2411975
implement only one aria-sort per table, add data attr for numeric values
sknep Jan 20, 2021
194cebc
update icon
sknep Jan 20, 2021
166566b
use data-sortable attribute instead of class, add statehood table exa…
sknep Jan 21, 2021
825b154
checkpoint - sort announcement
sknep Feb 2, 2021
d9aa757
Add sort buttons to DOM via JS
sknep Feb 2, 2021
9ae0d27
Simplify redundant classes/data attrs
sknep Feb 2, 2021
2592546
Change to SVG icons
sknep Feb 2, 2021
af7cec5
Aria adjustments
sknep Feb 3, 2021
b8f4d9d
Swap .find() for .filter() + [0] for IE
sknep Feb 3, 2021
767d108
Fix IE bugs, add theme settings + icons
sknep Feb 10, 2021
763be60
Fix var names
sknep Feb 10, 2021
aff1bd2
Use DS prefix
sknep Feb 10, 2021
2f3d1a1
Move back to data attributes, fix some cross-browser bugs
sknep Feb 10, 2021
52541b9
cleanup + notes, fix lints
sknep Feb 10, 2021
9196205
Add striped sortable background color
sknep Feb 10, 2021
60f689a
Remove unused icon
sknep Feb 11, 2021
32bae3b
Add some tests
sknep Feb 11, 2021
b472999
Add unit test for sort state svg node manipulation
sknep Feb 11, 2021
9628c4f
HTML cleanup
sknep Feb 11, 2021
3113176
fix typo
sknep Feb 11, 2021
e1a73a7
Fix typo.
Feb 11, 2021
b9e859b
use claseses instead of IDs
sknep Feb 11, 2021
7571ef4
Merge branch 'accelerator/3935-sortable-table' of https://github.com/…
sknep Feb 11, 2021
ec8d1ee
Update unit tests
sknep Feb 11, 2021
0f6750a
Prettier lint
sknep Feb 11, 2021
38529d5
HTML cleanup/indentation
sknep Feb 11, 2021
540972f
Clarify compareFunction
sknep Feb 11, 2021
d6bef95
Clean up the sort comparator function
sknep Feb 16, 2021
9563c96
Run prettier on table.js.
Feb 16, 2021
9085eae
Make arrowheads match on sort icon
sknep Feb 18, 2021
7739ea5
Improve mobile stacked table display on guidance page
sknep Feb 19, 2021
1209329
scope stacked styles to component
sknep Feb 19, 2021
894a2da
Merge branch 'uswds-2.11.0' into accelerator/3935-sortable-table
thisisdano Mar 4, 2021
a735528
Remove extra space
thisisdano Mar 4, 2021
1457d3d
Don't use a custom border for sorted columns
thisisdano Mar 8, 2021
fa3f008
Remove table-sort border styles from th
thisisdano Mar 8, 2021
fb9ac7f
Update deprecated assert.equal() to assert.strictEqual()
thisisdano Mar 10, 2021
9e2dec0
Use defaults for standard table colors
thisisdano Mar 10, 2021
96c0cef
Use default for sorted icon color
thisisdano Mar 10, 2021
929e595
Revert to default text color
thisisdano Mar 10, 2021
033cf2f
Sync settings
thisisdano Mar 10, 2021
4a22ecd
Calculate proper header colors, sorted and unsorted
thisisdano Mar 10, 2021
96c7aee
Account for sorting color edge cases
thisisdano Mar 10, 2021
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: 6 additions & 6 deletions spec/unit/accordion/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("accordion behavior", () => {
});

it('toggles button aria-expanded="true"', () => {
assert.equal(button.getAttribute(EXPANDED), "true");
assert.strictEqual(button.getAttribute(EXPANDED), "true");
});

it('toggles content "hidden" off', () => {
Expand All @@ -66,7 +66,7 @@ describe("accordion behavior", () => {
});

it('toggles button aria-expanded="false"', () => {
assert.equal(button.getAttribute(EXPANDED), "false");
assert.strictEqual(button.getAttribute(EXPANDED), "false");
});

it('toggles content "hidden" on', () => {
Expand All @@ -81,10 +81,10 @@ describe("accordion behavior", () => {
const target = document.getElementById(second.getAttribute(CONTROLS));
second.click();
// first button and section should be collapsed
assert.equal(button.getAttribute(EXPANDED), "false");
assert.strictEqual(button.getAttribute(EXPANDED), "false");
assert(content.hasAttribute(HIDDEN));
// second should be expanded
assert.equal(second.getAttribute(EXPANDED), "true");
assert.strictEqual(second.getAttribute(EXPANDED), "true");
assert(target.getAttribute(HIDDEN) !== true);
});

Expand All @@ -95,10 +95,10 @@ describe("accordion behavior", () => {
second.click();
button.click();

assert.equal(button.getAttribute(EXPANDED), "true");
assert.strictEqual(button.getAttribute(EXPANDED), "true");
assert(content.getAttribute(HIDDEN) !== true);
// second should be expanded
assert.equal(second.getAttribute(EXPANDED), "true");
assert.strictEqual(second.getAttribute(EXPANDED), "true");
assert(content.getAttribute(HIDDEN) !== true);
});
});
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/banner/banner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ describe("banner", () => {
});

it("initializes closed", () => {
assert.equal(header.classList.contains(EXPANDED_CLASS), false);
assert.equal(button.getAttribute(EXPANDED), "false");
assert.strictEqual(header.classList.contains(EXPANDED_CLASS), false);
assert.strictEqual(button.getAttribute(EXPANDED), "false");
assert(content.hasAttribute(HIDDEN));
});

it("opens when you click the button", () => {
button.click();
assert.equal(header.classList.contains(EXPANDED_CLASS), true);
assert.equal(button.getAttribute(EXPANDED), "true");
assert.strictEqual(header.classList.contains(EXPANDED_CLASS), true);
assert.strictEqual(button.getAttribute(EXPANDED), "true");
assert(content.getAttribute(HIDDEN) !== true);
});

it("closes when you click the button again", () => {
button.click();
button.click();
assert.equal(header.classList.contains(EXPANDED_CLASS), false);
assert.equal(button.getAttribute(EXPANDED), "false");
assert.strictEqual(header.classList.contains(EXPANDED_CLASS), false);
assert.strictEqual(button.getAttribute(EXPANDED), "false");
assert(content.hasAttribute(HIDDEN));
});
});
76 changes: 36 additions & 40 deletions spec/unit/character-count/character-count.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const CharacterCount = require('../../../src/js/components/character-count');
const fs = require("fs");
const path = require("path");
const assert = require("assert");
const CharacterCount = require("../../../src/js/components/character-count");

const { VALIDATION_MESSAGE, MESSAGE_INVALID_CLASS } = CharacterCount;

const TEMPLATE = fs.readFileSync(path.join(__dirname, '/character-count.template.html'));
const TEMPLATE = fs.readFileSync(
path.join(__dirname, "/character-count.template.html")
);

const EVENTS = {};

Expand All @@ -14,10 +16,10 @@ const EVENTS = {};
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.input = (el) => {
el.dispatchEvent(new KeyboardEvent('input', { bubbles: true }));
el.dispatchEvent(new KeyboardEvent("input", { bubbles: true }));
};

describe('character count component', () => {
describe("character count component", () => {
const { body } = document;

let root;
Expand All @@ -28,76 +30,70 @@ describe('character count component', () => {
body.innerHTML = TEMPLATE;
CharacterCount.on();

root = body.querySelector('.usa-character-count');
input = root.querySelector('.usa-character-count__field');
message = root.querySelector('.usa-character-count__message');
root = body.querySelector(".usa-character-count");
input = root.querySelector(".usa-character-count__field");
message = root.querySelector(".usa-character-count__message");
});

afterEach(() => {
body.textContent = '';
body.textContent = "";
CharacterCount.off(body);
});

it('adds initial message for the character count component', () => {
assert.equal(message.innerHTML, '20 characters allowed');
it("adds initial message for the character count component", () => {
assert.strictEqual(message.innerHTML, "20 characters allowed");
});

it('informs the user how many more characters they are allowed', () => {
input.value = '1';
it("informs the user how many more characters they are allowed", () => {
input.value = "1";

EVENTS.input(input);

assert.equal(message.innerHTML, '19 characters left');
assert.strictEqual(message.innerHTML, "19 characters left");
});

it('informs the user they are allowed a single character', () => {
input.value = '1234567890123456789';
it("informs the user they are allowed a single character", () => {
input.value = "1234567890123456789";

EVENTS.input(input);

assert.equal(message.innerHTML, '1 character left');
assert.strictEqual(message.innerHTML, "1 character left");
});

it('informs the user they are over the limit by a single character', () => {
input.value = '123456789012345678901';
it("informs the user they are over the limit by a single character", () => {
input.value = "123456789012345678901";

EVENTS.input(input);

assert.equal(message.innerHTML, '1 character over limit');
assert.strictEqual(message.innerHTML, "1 character over limit");
});

it('informs the user how many characters they will need to remove', () => {
input.value = '1234567890123456789012345';
it("informs the user how many characters they will need to remove", () => {
input.value = "1234567890123456789012345";

EVENTS.input(input);

assert.equal(message.innerHTML, '5 characters over limit');
assert.strictEqual(message.innerHTML, "5 characters over limit");
});

it('should show the component and input as valid when the input is under the limit', () => {
input.value = '1';
it("should show the component and input as valid when the input is under the limit", () => {
input.value = "1";

EVENTS.input(input);

assert.equal(input.validationMessage, '');
assert.equal(
assert.strictEqual(input.validationMessage, "");
assert.strictEqual(
message.classList.contains(MESSAGE_INVALID_CLASS),
false,
false
);
});

it('should show the component and input as invalid when the input is over the limit', () => {
input.value = '123456789012345678901';
it("should show the component and input as invalid when the input is over the limit", () => {
input.value = "123456789012345678901";

EVENTS.input(input);

assert.equal(
input.validationMessage,
VALIDATION_MESSAGE,
);
assert.equal(
message.classList.contains(MESSAGE_INVALID_CLASS),
true,
);
assert.strictEqual(input.validationMessage, VALIDATION_MESSAGE);
assert.strictEqual(message.classList.contains(MESSAGE_INVALID_CLASS), true);
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const CharacterCount = require('../../../src/js/components/character-count');
const fs = require("fs");
const path = require("path");
const assert = require("assert");
const CharacterCount = require("../../../src/js/components/character-count");

const TEMPLATE = fs.readFileSync(path.join(__dirname, '/valid-template-multiple-validators.template.html'));
const TEMPLATE = fs.readFileSync(
path.join(__dirname, "/valid-template-multiple-validators.template.html")
);

const EVENTS = {};

Expand All @@ -12,10 +14,10 @@ const EVENTS = {};
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.input = (el) => {
el.dispatchEvent(new KeyboardEvent('input', { bubbles: true }));
el.dispatchEvent(new KeyboardEvent("input", { bubbles: true }));
};

describe('character count component with multiple validators', () => {
describe("character count component with multiple validators", () => {
const { body } = document;

let root;
Expand All @@ -25,60 +27,63 @@ describe('character count component with multiple validators', () => {
body.innerHTML = TEMPLATE;
CharacterCount.on();

root = body.querySelector('.usa-character-count');
input = root.querySelector('.usa-character-count__field');
root = body.querySelector(".usa-character-count");
input = root.querySelector(".usa-character-count__field");
});

afterEach(() => {
body.textContent = '';
body.textContent = "";
CharacterCount.off(body);
});

it('assert that input constraint validation adds a validation message', () => {
input.value = 'abcd5';
it("assert that input constraint validation adds a validation message", () => {
input.value = "abcd5";

EVENTS.input(input);

assert.equal(input.validationMessage, 'Constraints not satisfied');
assert.strictEqual(input.validationMessage, "Constraints not satisfied");
});

it('assert that input constraint validation does not overwrite a custom message', () => {
input.setCustomValidity('There is an error');
input.value = 'abcd5';
it("assert that input constraint validation does not overwrite a custom message", () => {
input.setCustomValidity("There is an error");
input.value = "abcd5";

EVENTS.input(input);

assert.equal(input.validationMessage, 'There is an error');
assert.strictEqual(input.validationMessage, "There is an error");
});

it('should not affect the validation message when a custom error message is already present', () => {
input.setCustomValidity('There is an error');
input.value = 'abcdef';
it("should not affect the validation message when a custom error message is already present", () => {
input.setCustomValidity("There is an error");
input.value = "abcdef";

EVENTS.input(input);

assert.equal(input.validationMessage, 'There is an error');
assert.strictEqual(input.validationMessage, "There is an error");
});

it('should not affect the validation message when the input is already invalid', () => {
input.value = 'abcde5';
it("should not affect the validation message when the input is already invalid", () => {
input.value = "abcde5";

EVENTS.input(input);

assert.equal(input.validationMessage, 'Constraints not satisfied');
assert.strictEqual(input.validationMessage, "Constraints not satisfied");
});

it('should clear the validation message when input is only invalid by character count validation', () => {
input.value = 'abcdef';
it("should clear the validation message when input is only invalid by character count validation", () => {
input.value = "abcdef";

EVENTS.input(input);

assert.equal(input.validationMessage, CharacterCount.VALIDATION_MESSAGE);
assert.strictEqual(
input.validationMessage,
CharacterCount.VALIDATION_MESSAGE
);

input.value = 'abcde';
input.value = "abcde";

EVENTS.input(input);

assert.equal(input.validationMessage, '');
assert.strictEqual(input.validationMessage, "");
});
});
34 changes: 18 additions & 16 deletions spec/unit/character-count/valid-template-no-maxlength.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const CharacterCount = require('../../../src/js/components/character-count');
const fs = require("fs");
const path = require("path");
const assert = require("assert");
const CharacterCount = require("../../../src/js/components/character-count");

const TEMPLATE = fs.readFileSync(path.join(__dirname, '/valid-template-no-maxlength.template.html'));
const TEMPLATE = fs.readFileSync(
path.join(__dirname, "/valid-template-no-maxlength.template.html")
);

const EVENTS = {};

Expand All @@ -12,10 +14,10 @@ const EVENTS = {};
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.input = (el) => {
el.dispatchEvent(new KeyboardEvent('input', { bubbles: true }));
el.dispatchEvent(new KeyboardEvent("input", { bubbles: true }));
};

describe('character count component without maxlength', () => {
describe("character count component without maxlength", () => {
const { body } = document;

let root;
Expand All @@ -26,25 +28,25 @@ describe('character count component without maxlength', () => {
body.innerHTML = TEMPLATE;
CharacterCount.on();

root = body.querySelector('.usa-character-count');
input = root.querySelector('.usa-character-count__field');
message = root.querySelector('.usa-character-count__message');
root = body.querySelector(".usa-character-count");
input = root.querySelector(".usa-character-count__field");
message = root.querySelector(".usa-character-count__message");
});

afterEach(() => {
body.textContent = '';
body.textContent = "";
CharacterCount.off(body);
});

it('should not update an initial message for the character count component', () => {
assert.equal(message.innerHTML, '');
it("should not update an initial message for the character count component", () => {
assert.strictEqual(message.innerHTML, "");
});

it('should not inform the user of remaining characters when typing', () => {
input.value = '1';
it("should not inform the user of remaining characters when typing", () => {
input.value = "1";

EVENTS.input(input);

assert.equal(message.innerHTML, '');
assert.strictEqual(message.innerHTML, "");
});
});
Loading