Skip to content

Commit

Permalink
Merge pull request #200 from CrowdStrike/add-select-component-tony
Browse files Browse the repository at this point in the history
Add Combobox component to Toucan Core & Toucan Form
  • Loading branch information
ynotdraw authored Jul 14, 2023
2 parents 8bb08f0 + 212cd77 commit c0b8d13
Show file tree
Hide file tree
Showing 39 changed files with 3,593 additions and 30 deletions.
61 changes: 61 additions & 0 deletions .changeset/twelve-gifts-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
'@crowdstrike/ember-toucan-core': patch
'@crowdstrike/ember-toucan-form': patch
---

Added a `Combobox` component to both core and form packages.

If you're using `toucan-core`, the control and field components are exposed:

```hbs
<Form::Controls::Combobox
@onChange={{this.onChange}}
@options={{this.options}}
@contentClass='z-10'
@selected={{this.selected}}
@optionKey='label'
@noResultsText='No results'
placeholder='Colors'
as |combobox|
>
<combobox.Option>
{{combobox.option.label}}
</combobox.Option>
</Form::Controls::Combobox>
<Form::Fields::Combobox
@contentClass='z-10'
@error={{this.errorMessage}}
@hint='Type "blue" into the field'
@label='Label'
@noResultsText='No results'
@onChange={{this.onChange}}
@optionKey='label'
@options={{this.options}}
@selected={{this.selected}}
placeholder='Colors'
as |combobox|
>
<combobox.Option>
{{combobox.option.label}}
</combobox.Option>
</Form::Fields::Combobox>
```

If you're using `toucan-form`, the component is exposed via:

```hbs
<ToucanForm as |form|>
<form.Combobox
@label='Combobox'
@name='combobox'
@options={{options}}
data-combobox
as |combobox|
>
<combobox.Option data-option>{{combobox.option}}</combobox.Option>
</form.Combobox>
</ToucanForm>
```

For more information on using these components, view [the docs](https://ember-toucan-core.pages.dev/docs/components/combobox).
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ jobs:
- ember-release
- ember-beta
- ember-canary
- "'ember-release + embroider-optimized'"
- "'ember-lts-4.8 + embroider-optimized'"
# @todo Temporarily disabling embroider optimized tests due to https://github.com/CrowdStrike/ember-toucan-core/issues/210
# - "'ember-release + embroider-optimized'"
# - "'ember-lts-4.8 + embroider-optimized'"

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"ember-browser-services": "^4.0.4",
"ember-modifier": "^4.1.0",
"ember-resources": "^6.0.0",
"ember-velcro": "^2.1.0",
"highlight.js": "^11.6.0",
"highlightjs-glimmer": "^2.0.0",
"tracked-built-ins": "^3.1.0"
Expand Down
74 changes: 74 additions & 0 deletions docs/components/combobox-field/demo/base-demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
```hbs template
<Form::Fields::Combobox
@contentClass='z-10'
@error={{this.errorMessage}}
@hint='Type "blue" into the field'
@label='Label'
@noResultsText='No results'
@onChange={{this.onChange}}
@optionKey='label'
@options={{this.options}}
@selected={{this.selected}}
placeholder='Colors'
as |combobox|
>
<combobox.Option>
{{combobox.option.label}}
</combobox.Option>
</Form::Fields::Combobox>
```

```js component
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class extends Component {
@tracked selected;
@tracked errorMessage;

options = [
{
label: 'Blue',
name: 'blue',
},
{
label: 'Green',
name: 'green',
},
{
label: 'Yellow',
name: 'yellow',
},
{
label: 'Orange',
name: 'orange',
},
{
label: 'Red',
name: 'red',
},
{
label: 'Purple',
name: 'purple',
},
{
label: 'Teal',
name: 'teal',
},
];

@action
onChange(option) {
this.selected = option;
console.log(option);

if (option.label !== 'Blue') {
this.errorMessage = 'Please select "Blue"';
return;
}

this.errorMessage = null;
}
}
```
Loading

0 comments on commit c0b8d13

Please sign in to comment.