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

Remove prescriptive rendering of FASTSelect and adds placeholder content #6732

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5bb380d
select: removes prescriptive rendering of select as listbox
brianchristopherbrady May 11, 2023
3b44f66
select: updates style tokens
brianchristopherbrady May 11, 2023
ec819af
select: adds test coverage
brianchristopherbrady May 11, 2023
7d39fbc
select: updates README
brianchristopherbrady May 11, 2023
ac1ba17
Change files
brianchristopherbrady May 11, 2023
bde5e7a
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady May 11, 2023
67f85ed
select: merge
brianchristopherbrady May 11, 2023
8a456cf
Merge branch 'user/brianbrady/select-remove-prescriptive-rendering' o…
brianchristopherbrady May 12, 2023
707dcd8
select: updates styles
brianchristopherbrady May 12, 2023
c1f7791
select: updates comments
brianchristopherbrady May 12, 2023
f2592e0
select: optimzes class method
brianchristopherbrady May 12, 2023
9af2e44
select, optimizes class method, updates comments
brianchristopherbrady May 12, 2023
587ec5d
select: optimizes placeholder logic
brianchristopherbrady Jul 17, 2023
0a90874
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Jul 17, 2023
dfd0283
select: fixes conditional
brianchristopherbrady Jul 31, 2023
29cc9ac
Merge branch 'user/brianbrady/select-remove-prescriptive-rendering' o…
brianchristopherbrady Jul 31, 2023
2a796e2
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Aug 3, 2023
6f6af15
Optimized event handling by using a return condition instead of calli…
brianchristopherbrady Aug 17, 2023
0a332ce
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Aug 17, 2023
9124a78
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Aug 17, 2023
274bab4
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Sep 21, 2023
d57eb60
Merge branch 'master' into user/brianbrady/select-remove-prescriptive…
brianchristopherbrady Oct 2, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "select: removes prescriptive rendering of select as listbox",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "patch"
}
17 changes: 10 additions & 7 deletions packages/web-components/fast-foundation/src/select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ See [listbox-option](/docs/components/listbox-option) for more information.

#### Attributes

| Name | Field | Inherited From |
| ---- | -------- | -------------- |
| | multiple | FASTListbox |
| Name | Field | Inherited From |
| ---- | ------------ | -------------- |
| | multiple | FASTListbox |

<hr/>

Expand Down Expand Up @@ -148,6 +148,7 @@ See [listbox-option](/docs/components/listbox-option) for more information.
| `disabled` | public | `boolean` | | The disabled state of the listbox. | FASTListbox |
| `selectedIndex` | public | `number` | `-1` | The index of the selected option. | FASTListbox |
| `selectedOptions` | public | `FASTListboxOption[]` | `[]` | A collection of the selected options. | FASTListbox |
| `listboxMode` | public | `boolean` | `false` | Indicates if the select renders as a listbox only | FASTSelect |

#### Methods

Expand All @@ -167,10 +168,12 @@ See [listbox-option](/docs/components/listbox-option) for more information.

#### Attributes

| Name | Field | Inherited From |
| ------ | -------- | -------------- |
| `open` | open | |
| | multiple | FASTListbox |
| Name | Field | Inherited From |
| -------------- | ----------- | -------------- |
| `open` | open | |
| `multiple` | multiple | FASTListbox |
| `listbox-mode` | listboxMode | FASTSelect |


#### CSS Parts

Expand Down
139 changes: 139 additions & 0 deletions packages/web-components/fast-foundation/src/select/select.pw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,68 @@ test.describe("Select", () => {
await expect(listbox).toBeVisible();
});

test("pressing Enter key while closed should open the dropdown", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

await element.evaluate((node: FASTSelect) => {
const event = new KeyboardEvent("keydown", { key: "Enter" });
node.dispatchEvent(event);
});

await expect(element).toHaveBooleanAttribute("open");
});

test("should select an option when the Enter key is pressed and the select is open", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

// Open the select
await element.evaluate((node: FASTSelect) => {
node.open = true;
});

await element.evaluate((node: FASTSelect) => {
const event = new KeyboardEvent("keydown", { key: "Enter" });
node.dispatchEvent(event);
});

await expect(element).toHaveJSProperty("selectedIndex", 0);
});

test("pressing Escape key while open should close the dropdown", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select open>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

await element.evaluate((node: FASTSelect) => {
const event = new KeyboardEvent("keydown", { key: "Escape" });
node.dispatchEvent(event);
});

await expect(element).not.toHaveBooleanAttribute("open");
});

["input", "change"].forEach(eventName => {
[
{ expectedValue: "Option 2", key: "ArrowDown" },
Expand Down Expand Up @@ -513,4 +575,81 @@ test.describe("Select", () => {

await expect(element).toHaveJSProperty("displayValue", "textContent value");
});

test("should set the displayValue to the selected options separated by commas when the multiple attribute is present", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select multiple>
<fast-option selected>Option 1</fast-option>
<fast-option selected>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

await expect(element).toHaveJSProperty("displayValue", "Option 1, Option 2");
});

test("should not close on click when the multiple attribute is present", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select multiple>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

const listbox = element.locator(".listbox");

// Open the select
await element.evaluate((node: FASTSelect) => {
node.open = true;
});

// Simulate a click on the select
await element.click();

await expect(element).toHaveBooleanAttribute("open");
await expect(listbox).toBeVisible();
});

test("when listbox-mode attribute is present, the select renders the listbox only without control", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select listbox-mode>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-select>
`;
});

const listbox = element.locator(".listbox");
const control = element.locator(".control");

await expect(listbox).toBeVisible();
await expect(control).not.toBeVisible();
});

test("should display the placeholder when no option is selected", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-select placeholder="Select an option">
<fast-option value="1">Option 1</fast-option>
<fast-option value="2">Option 2</fast-option>
<fast-option value="3">Option 3</fast-option>
</fast-select>
`;
});

await expect(element).toHaveJSProperty("displayValue", "Select an option");

await element.evaluate<void, FASTSelect>(node => {
node.value = "2";
});

await expect(element).toHaveJSProperty("displayValue", "Option 2");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function selectTemplate<T extends FASTSelect>(
aria-expanded="${x => x.ariaExpanded}"
aria-haspopup="${x => (x.collapsible ? "listbox" : null)}"
aria-multiselectable="${x => x.ariaMultiSelectable}"
?listbox-mode="${x => x.listboxMode}"
?open="${x => x.open}"
role="combobox"
tabindex="${x => (!x.disabled ? "0" : null)}"
Expand All @@ -29,7 +30,7 @@ export function selectTemplate<T extends FASTSelect>(
@mousedown="${(x, c) => x.mousedownHandler(c.event as MouseEvent)}"
>
${when(
x => x.collapsible,
x => !x.listboxMode && x.collapsible,
html<T>`
<div
class="control"
Expand Down Expand Up @@ -58,9 +59,18 @@ export function selectTemplate<T extends FASTSelect>(
part="listbox"
role="listbox"
?disabled="${x => x.disabled}"
?hidden="${x => (x.collapsible ? !x.open : false)}"
?hidden="${x =>
!x.listboxMode ? (x.collapsible ? !x.open : false) : false}"
${ref("listbox")}
>
${when(
x => x.placeholder,
html<T>`
<option disabled hidden ${ref("placeholderOption")}>
${x => x.placeholder}
</option>
`
)}
<slot
${slotted({
filter: FASTListbox.slottedOptionFilter,
Expand Down
Loading
Loading