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

USWDS-3479 Combo Box Subsequent Selection #3505

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d454f43
3470 prettier / input event / stubs
wbyoko Jun 1, 2020
11a22fb
3479 Subsequent Selection
wbyoko Jun 2, 2020
7734ab6
3479 Subsequent Selection
wbyoko Jun 2, 2020
e9af7ba
3479 Subsequent Selection
wbyoko Jun 3, 2020
959104e
3479 use select value to find selected value
wbyoko Jun 3, 2020
2e09ea6
3479 stubs
wbyoko Jun 3, 2020
7d96b3c
Merge branch 'develop' of github.com:uswds/uswds into 10x-forms/3479-…
wbyoko Jun 8, 2020
7f6f6cd
3479 update styles
wbyoko Jun 8, 2020
3252f78
3479 Update combo box
wbyoko Jun 9, 2020
49ffc05
Merge branch '10x-forms/3490-mouseover-selection' into 10x-forms/3479…
wbyoko Jun 9, 2020
21ff046
Merge branch '3477-3482-combobox-data-attributes' into 10x-forms/3479…
wbyoko Jun 9, 2020
9e068fa
Merge branch '10x-forms/3474-disabled-combo-box' into 10x-forms/3479-…
wbyoko Jun 9, 2020
689d512
3479 Update tests
wbyoko Jun 9, 2020
86a2e57
aria labels for new buttons
wbyoko Jun 9, 2020
64dc875
Merge branch '10x-forms/combo-box-updates' into 10x-forms/3479-combob…
wbyoko Jun 10, 2020
2f25126
3479 reset selection
wbyoko Jun 10, 2020
13bcc0c
3479 manage tabindex
wbyoko Jun 10, 2020
1d700a4
3479 Icon hover
wbyoko Jun 10, 2020
a7f7d86
3479 update disable / enable support
wbyoko Jun 11, 2020
0df86c3
3479 attempt preload
wbyoko Jun 11, 2020
c90f0cd
3479 update the size of icons
wbyoko Jun 11, 2020
916b33b
3479 Update separator color
wbyoko Jun 11, 2020
caacf4f
3479 swap focused / selected
wbyoko Jun 15, 2020
8112f28
Merge branch 'develop' of github.com:uswds/uswds into 10x-forms/3479-…
wbyoko Jun 16, 2020
8ea296c
Merge branch '10x-forms/combo-box-updates' into 10x-forms/3479-combob…
wbyoko Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
195 changes: 30 additions & 165 deletions spec/unit/combo-box/combo-box-change-event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,117 +3,12 @@ const path = require("path");
const sinon = require("sinon");
const assert = require("assert");
const ComboBox = require("../../../src/js/components/combo-box");
const EVENTS = require("./events");

const TEMPLATE = fs.readFileSync(
path.join(__dirname, "/combo-box-change-event.template.html")
);

const EVENTS = {};

/**
* send a click event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.click = el => {
const evt = new MouseEvent("click", {
view: el.ownerDocument.defaultView,
bubbles: true,
cancelable: true
});
el.dispatchEvent(evt);
};

/**
* send a focusout event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.focusout = el => {
const evt = new Event("focusout", {
bubbles: true,
cancelable: true
});
el.dispatchEvent(evt);
};

/**
* send a keyup A event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keyupA = el => {
const evt = new KeyboardEvent("keyup", {
bubbles: true,
key: "a",
keyCode: 65
});
el.dispatchEvent(evt);
};

/**
* send a keyup O event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keyupO = el => {
const evt = new KeyboardEvent("keyup", {
bubbles: true,
key: "o",
keyCode: 79
});
el.dispatchEvent(evt);
};

/**
* send a keydown Enter event
* @param {HTMLElement} el the element to sent the event to
* @returns {{preventDefaultSpy: sinon.SinonSpy<[], void>}}
*/
EVENTS.keydownEnter = el => {
const evt = new KeyboardEvent("keydown", {
bubbles: true,
key: "Enter",
keyCode: 13
});
const preventDefaultSpy = sinon.spy(evt, "preventDefault");
el.dispatchEvent(evt);
return { preventDefaultSpy };
};

/**
* send a keydown Escape event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keydownEscape = el => {
const evt = new KeyboardEvent("keydown", {
bubbles: true,
key: "Escape",
keyCode: 27
});
el.dispatchEvent(evt);
};

/**
* send a keydown ArrowDown event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keydownArrowDown = el => {
const evt = new KeyboardEvent("keydown", {
bubbles: true,
key: "ArrowDown"
});
el.dispatchEvent(evt);
};

/**
* send a keydown Tab event
* @param {HTMLElement} el the element to sent the event to
*/
EVENTS.keydownTab = el => {
const evt = new KeyboardEvent("keydown", {
bubbles: true,
key: "Tab"
});
el.dispatchEvent(evt);
};

describe("combo box component change event dispatch", () => {
const { body } = document;

Expand Down Expand Up @@ -178,86 +73,56 @@ describe("combo box component change event dispatch", () => {
);
});

it("should emit change events when clearing input values when an incomplete item is remaining on blur", () => {
it("should emit change events when resetting input values when an incomplete item is submitted through enter", () => {
select.value = "value-ActionScript";
input.value = "a";
EVENTS.keyupA(input);
assert.ok(!list.hidden, "should display the option list");

EVENTS.keydownTab(input);
EVENTS.focusout(input);

assert.equal(select.value, "", "should clear the value on the select");
assert.equal(input.value, "", "should clear the value on the input");
assert.ok(selectChangeSpy.called, "should have dispatched a change event");
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});

it("should emit change events when clearing input values when an incomplete item is submitted through enter", () => {
select.value = "value-ActionScript";
input.value = "a";
EVENTS.keyupA(input);
EVENTS.input(input);
assert.ok(!list.hidden, "should display the option list");

EVENTS.keydownEnter(input);

assert.equal(select.value, "", "should clear the value on the select");
assert.equal(input.value, "", "should clear the value on the input");
assert.ok(selectChangeSpy.called, "should have dispatched a change event");
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});

it("should not emit change events when closing the list but not the clear the input value when escape is performed while the list is open", () => {
select.value = "value-ActionScript";
input.value = "a";
EVENTS.keyupA(input);
assert.ok(!list.hidden, "should display the option list");

EVENTS.keydownEscape(input);

assert.equal(select.value, "value-ActionScript");
assert.equal(
select.value,
"value-ActionScript",
"should not change the value of the select"
input.value,
"ActionScript",
"should reset the value on the input"
);
assert.equal(input.value, "a", "should not change the value in the input");
assert.ok(
selectChangeSpy.notCalled,
"should not have dispatched a change event"
);
assert.ok(
inputChangeSpy.notCalled,
"should not have dispatched a change event"
);
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});

it("should emit change events when setting the input value when a complete selection is submitted by clicking away", () => {
it("should emit change events when closing the list but not the clear the input value when escape is performed while the list is open", () => {
select.value = "value-ActionScript";
input.value = "go";
EVENTS.keyupO(input);
input.value = "a";
EVENTS.input(input);
assert.ok(!list.hidden, "should display the option list");

EVENTS.keydownTab(input);
EVENTS.focusout(input);
EVENTS.keydownEscape(input);

assert.equal(
select.value,
"value-Go",
"should set that item to being the select option"
"value-ActionScript",
"should not change the value of the select"
);
assert.equal(
input.value,
"Go",
"should set that item to being the input value"
"ActionScript",
"should reset the value in the input"
);
assert.ok(
selectChangeSpy.notCalled,
"should not have dispatched a change event"
);
assert.ok(selectChangeSpy.called, "should have dispatched a change event");
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});

it("should emit change events when setting the input value when a complete selection is submitted by pressing enter", () => {
select.value = "value-ActionScript";
input.value = "go";
EVENTS.keyupO(input);
EVENTS.input(input);
assert.ok(!list.hidden, "should display the option list");

EVENTS.keydownEnter(input);
Expand All @@ -280,7 +145,7 @@ describe("combo box component change event dispatch", () => {
select.value = "value-JavaScript";
input.value = "la";

EVENTS.keyupA(input);
EVENTS.input(input);
EVENTS.keydownArrowDown(input);
const focusedOption = document.activeElement;
assert.equal(
Expand All @@ -300,11 +165,11 @@ describe("combo box component change event dispatch", () => {
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});

it("should not emit change events when pressing escape from a focused item", () => {
it("should emit change events when pressing escape from a focused item", () => {
select.value = "value-JavaScript";
input.value = "la";

EVENTS.keyupA(input);
EVENTS.input(input);
assert.ok(
!list.hidden && list.children.length,
"should display the option list with options"
Expand All @@ -319,20 +184,20 @@ describe("combo box component change event dispatch", () => {
EVENTS.keydownEscape(focusedOption);

assert.ok(list.hidden, "should hide the option list");
assert.equal(list.children.length, 0, "should empty the option list");
assert.equal(
select.value,
"value-JavaScript",
"should not change the value of the select"
);
assert.equal(input.value, "la", "should not change the value in the input");
assert.ok(
selectChangeSpy.notCalled,
"should not have dispatched a change event"
assert.equal(
input.value,
"JavaScript",
"should reset the value in the input"
);
assert.ok(
inputChangeSpy.notCalled,
selectChangeSpy.notCalled,
"should not have dispatched a change event"
);
assert.ok(inputChangeSpy.called, "should have dispatched a change event");
});
});
7 changes: 1 addition & 6 deletions spec/unit/combo-box/combo-box-change-event.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
>Your preferred programming language:
</label>
<div class="usa-combo-box">
<select
id="combo-box"
name="combo-box"
class="usa-select usa-combo-box__select"
required
>
<select id="combo-box" name="combo-box" class="usa-select">
<option value="">Select one...</option>
<option value="value-ActionScript">ActionScript</option>
<option value="value-AppleScript">AppleScript</option>
Expand Down
6 changes: 1 addition & 5 deletions spec/unit/combo-box/combo-box-default-value.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
>Your preferred programming language:
</label>
<div class="usa-combo-box" data-default-value="value-Go">
<select
id="combo-box"
name="combo-box"
class="usa-select usa-combo-box__select"
>
<select id="combo-box" name="combo-box" class="usa-select">
<option value="">Select a language...</option>
<option value="value-ActionScript">ActionScript</option>
<option value="value-AppleScript">AppleScript</option>
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/combo-box/combo-box-disabled.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("combo box component - disabled enhancement", () => {
let root;
let input;
let select;
let toggle;
let list;

beforeEach(() => {
Expand All @@ -36,6 +37,7 @@ describe("combo box component - disabled enhancement", () => {
root = body.querySelector(".usa-combo-box");
input = root.querySelector(".usa-combo-box__input");
select = root.querySelector(".usa-combo-box__select");
toggle = root.querySelector(".usa-combo-box__toggle-list");
list = root.querySelector(".usa-combo-box__list");
});

Expand Down Expand Up @@ -63,4 +65,17 @@ describe("combo box component - disabled enhancement", () => {

assert.ok(list.hidden, "should not display the option list");
});

it("should not show the list when clicking the disabled button", () => {
EVENTS.click(toggle);

assert.ok(list.hidden, "should not display the option list");
});

it("should show the list when clicking the input once the component has been enabled", () => {
ComboBox.enable(root);
EVENTS.click(input);

assert.ok(!list.hidden, "should display the option list");
});
});
5 changes: 3 additions & 2 deletions spec/unit/combo-box/combo-box-disabled.template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<form class="usa-form">
<label class="usa-label" for="combobox">Your preferred programming language:
<label class="usa-label" for="combobox"
>Your preferred programming language:
</label>
<div class="usa-combo-box">
<select id="combo-box" name="combo-box" class="usa-select" disabled>
Expand Down Expand Up @@ -29,4 +30,4 @@
<option value="value-Scheme">Scheme</option>
</select>
</div>
</form>
</form>
6 changes: 1 addition & 5 deletions spec/unit/combo-box/combo-box-placeholder.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
>Your preferred programming language:
</label>
<div class="usa-combo-box" data-placeholder="Select one...">
<select
id="combo-box"
name="combo-box"
class="usa-select usa-combo-box__select"
>
<select id="combo-box" name="combo-box" class="usa-select">
<option value="">Select a language...</option>
<option value="value-ActionScript">ActionScript</option>
<option value="value-AppleScript">AppleScript</option>
Expand Down