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(combobox): add combobox pattern #3894

Merged
merged 23 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
960ecd1
feat(combobox): begin working branch for combobox additions
Westbrook Oct 3, 2021
5716991
feat(combobox): add size attribute (#3887)
najikahalsema Dec 19, 2023
2d50dab
chore: add benchmark test for lightdom combobox (#3898)
najikahalsema Dec 21, 2023
f188633
test(combobox): update data management tests for current API
Westbrook Dec 31, 2023
7f7b96a
test(combobox): get more tests passing and skip tests that will be vi…
Jan 4, 2024
db2a6c4
chore(combobox): cleanup unused code (#3922)
Jan 9, 2024
f5cde24
fix(combobox): add support for external tooltip elements (#3930)
Jan 9, 2024
1afa073
fix(combobox): allow intern Menu to hold a selection when autocomplet…
Jan 19, 2024
03570a9
test(combobox): add accessibility tests (#3953)
najikahalsema Jan 29, 2024
fb16573
test(combobox): fulfil accessibility contract (#3974)
najikahalsema Jan 29, 2024
6f0c907
chore(bundle): include combobox
Westbrook Jan 30, 2024
07922c5
chore(combobox): clean up property availability and types
Jan 30, 2024
32a6c29
refactor(combobox): default "autocomplete" to "none"
Westbrook Jan 30, 2024
ec89bc2
docs: correct story configuration
Westbrook Jan 30, 2024
46ba27d
docs(combobox): create initial documentation
hunterloftis Jan 29, 2024
ba42dfa
docs(combobox): apply docs feedback
hunterloftis Jan 30, 2024
f7de1f8
docs(combobox): use only working examples in live mode
hunterloftis Jan 30, 2024
f6c3527
fix(combobox): maintain focus on input element when toggling menu
hunterloftis Jan 30, 2024
6faa900
docs(combobox): improve clarity
hunterloftis Jan 31, 2024
7ee72bb
ci: update golden images cache
Westbrook Jan 31, 2024
1f9753b
docs(combobox): add story demonstrating controlled-component usage (#…
hunterloftis Feb 1, 2024
b8a95bb
fix(combobox): add support for "readonly" and "disabled"
Feb 1, 2024
69a9fdf
fix(combobox): correct value to itemText interchange when something i…
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ executors:
parameters:
current_golden_images_hash:
type: string
default: 0ee048a172d6cdf6f7b82def40e024f69c8abb6b
default: 3f18b907cc7ccfebda57963ffe10e1c132c17761
wireit_cache_name:
type: string
default: wireit
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@
"tools/**/*.ts",
"!tools/**/*.d.ts",
"tasks/esbuild-packages.js",
"tasks/ts-tools.js"
"tasks/ts-tools.js",
"packages/**/exports.json",
"tools/**/exports.json"
],
"output": [
"packages/**/*.js",
Expand Down
162 changes: 162 additions & 0 deletions packages/combobox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
## Description

An `<sp-combobox>` allows users to filter lists to only the options matching a query. It's composed of a textfield, a picker button, and child menu items.

### Usage

[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/combobox?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/combobox)
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/combobox?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/combobox)

```
yarn add @spectrum-web-components/combobox
```

Import the side effectful registration of `<sp-combobox>` via:

```
import '@spectrum-web-components/combobox/sp-combobox.js';
```

When looking to leverage the `Combobox` base class as a type and/or for extension purposes, do so via:

```
import { Combobox } from '@spectrum-web-components/combobox';
```

## Sizes

<sp-tabs selected="m" auto label="Size Attribute Options">
<sp-tab value="s">Small</sp-tab>
<sp-tab-panel value="s">

```html
<sp-combobox size="s" label="Color">
<sp-menu-item value="red">Red</sp-menu-item>
<sp-menu-item value="green">Green</sp-menu-item>
<sp-menu-item value="blue">Blue</sp-menu-item>
</sp-combobox>
```

</sp-tab-panel>
<sp-tab value="m">Medium</sp-tab>
<sp-tab-panel value="m">

```html
<sp-combobox size="m" label="Color">
<sp-menu-item value="red">Red</sp-menu-item>
<sp-menu-item value="green">Green</sp-menu-item>
<sp-menu-item value="blue">Blue</sp-menu-item>
</sp-combobox>
```

</sp-tab-panel>
<sp-tab value="l">Large</sp-tab>
<sp-tab-panel value="l">

```html
<sp-combobox size="l" label="Color">
<sp-menu-item value="red">Red</sp-menu-item>
<sp-menu-item value="green">Green</sp-menu-item>
<sp-menu-item value="blue">Blue</sp-menu-item>
</sp-combobox>
```

</sp-tab-panel>
<sp-tab value="xl">Extra Large</sp-tab>
<sp-tab-panel value="xl">

```html
<sp-combobox size="xl" label="Color">
<sp-menu-item value="red">Red</sp-menu-item>
<sp-menu-item value="green">Green</sp-menu-item>
<sp-menu-item value="blue">Blue</sp-menu-item>
</sp-combobox>
```

</sp-tab-panel>
</sp-tabs>

## Labeling

A combobox must be labeled.
Typically, you should render a visible label via `<sp-field-label>`.
For exceptional cases, provide an accessible label via the `label` attribute.

```html
<sp-field-label for="color">Color</sp-field-label>
<sp-combobox id="color">
<sp-menu-item value="red">Red</sp-menu-item>
<sp-menu-item value="green">Green</sp-menu-item>
<sp-menu-item value="blue">Blue</sp-menu-item>
</sp-combobox>
```

## Providing options

Combobox options are presented as a popup menu.
Menu items can be provided via markup as `<sp-menu-item>` children, or by assigning an array to the `options` property of an `<sp-combobox>`.

### Options property

Instead of providing `<sp-menu-item>` children, you can assign an array of `ComboboxOptions` to the `options` property, and `<sp-combobox>` will create matching menu items:

```html-no-demo
<sp-combobox id="color" label="Color"></sp-combobox>

<script>
document.getElementById('color').options = [
{ value: "red", itemText: "Red" },
{ value: "green", itemText: "Green" },
{ value: "blue", itemText: "Blue" }
];
</script>
```

### Dynamic options

When you replace the `options` Array, or add/remove `<sp-menu-item>` children, the `<sp-combobox>` will detect that change and update its popup menu contents.
For example, using [Lit](https://lit.dev/):

```ts
render() {
return html`<sp-combobox label="Color" .options=${this.colorOptions}></sp-combobox>`;
}

mutate() {
this.colorOptions = [
...this.colorOptions,
{ value: 'purple', itemText: 'Purple' }
];
}
```

## Autocomplete

The text in an `<sp-combobox>` is editable, and the string the user has typed in will become the `value` of the combobox unless the user selects a different value in the popup menu.

### None

`autocomplete="none"`

The suggested popup menu items will remain the same regardless of the currently-input value.
Whenever the currently-typed input exactly matches the `value` of a popup menu item, that item is automatically selected.

### List

`autocomplete="list"`

The popup menu items are filtered to only those completing the currently-input value.

## Focus and Accessibility

The combobox supports both mouse and keyboard navigation.
Mobile behavior is currently unspecified.

When an `<sp-combobox>` is focused, pressing the down arrow moves focus to the first menu item in the popup menu.
The up and down arrows then move between available menu items.

The escape key dismisses the popup menu if open.
Otherwise, it clears the combobox's textfield.

The enter key sets the `value` of the focused `<sp-combobox>`.
If the popup menu is open, the value is set to the `value` of the selected menu item, returning focus back to the combobox's textfield.
4 changes: 4 additions & 0 deletions packages/combobox/exports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"./src/*": "./src/*",
"./sp-combobox.js": "./sp-combobox.js"
}
77 changes: 77 additions & 0 deletions packages/combobox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "@spectrum-web-components/combobox",
"version": "0.0.1",
"publishConfig": {
"access": "public"
},
"description": "",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/adobe/spectrum-web-components.git",
"directory": "packages/combobox"
},
"author": "",
"homepage": "https://adobe.github.io/spectrum-web-components/components/combobox",
"bugs": {
"url": "https://github.com/adobe/spectrum-web-components/issues"
},
"main": "src/index.js",
"module": "src/index.js",
"type": "module",
"exports": {
".": {
"development": "./src/index.dev.js",
"default": "./src/index.js"
},
"./package.json": "./package.json",
"./src/Combobox.js": {
"development": "./src/Combobox.dev.js",
"default": "./src/Combobox.js"
},
"./src/combobox.css.js": "./src/combobox.css.js",
"./src/index.js": {
"development": "./src/index.dev.js",
"default": "./src/index.js"
},
"./sp-combobox.js": {
"development": "./sp-combobox.dev.js",
"default": "./sp-combobox.js"
}
},
"scripts": {
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
},
"files": [
"*.d.ts",
"*.js",
"*.js.map",
"/src/",
"custom-elements.json"
],
"keywords": [
"spectrum css",
"web components",
"lit-element",
"lit-html"
],
"dependencies": {
"@spectrum-web-components/action-button": "^0.40.1",
"@spectrum-web-components/base": "^0.40.1",
"@spectrum-web-components/icon": "^0.40.1",
"@spectrum-web-components/icons-ui": "^0.40.1",
"@spectrum-web-components/menu": "^0.40.1",
"@spectrum-web-components/overlay": "^0.40.1",
"@spectrum-web-components/picker-button": "^0.40.1",
"@spectrum-web-components/popover": "^0.40.1",
"@spectrum-web-components/textfield": "^0.40.1"
},
"devDependencies": {
"@spectrum-css/combobox": "^2.0.46"
},
"types": "./src/index.d.ts",
"sideEffects": [
"./sp-*.js",
"./sp-*.ts"
]
}
21 changes: 21 additions & 0 deletions packages/combobox/sp-combobox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { Combobox } from './src/Combobox.js';

customElements.define('sp-combobox', Combobox);

declare global {
interface HTMLElementTagNameMap {
'sp-combobox': Combobox;
}
}
Loading
Loading