Skip to content

Commit

Permalink
feat(mdc-select): Implement native select
Browse files Browse the repository at this point in the history
  • Loading branch information
pgbross authored and pgbross committed Apr 5, 2018
1 parent dfb923a commit 755ffac
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 835 deletions.
158 changes: 72 additions & 86 deletions components/select/README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,72 @@
## Usage

```html
<mdc-select v-model="selected" label=">Please select one">
<mdc-option>A</mdc-option>
<mdc-option>B</mdc-option>
<mdc-option>C</mdc-option>
</mdc-select>
<span>Selected: {{ selected }}</span>
```

```javascript
var vm = new Vue({
data () {
return {
selected: '',
}
}
})
```

> For better cross-device experiennce, `<mdc-select>` will switch from menu to
> native rendering based on the media query
> `(max-width: 600px) and (pointer: coarse)`.
### mdc-select

| props | Type | Default | Description |
| ---------- | --------------- | ------- | -------------------------------------------- |
| `disabled` | Boolean | false | whether this select is disabled |
| `label` | String | | the selection label |
| `value` | [String, Array] | | bind with v-model (update on `change` event) |
| `multiple` | Boolean | | whether the select accept multiple values |
| `max-size` | Boolean | 4 | multi select max size |
| `native` | String | | force native select rendering |
| `name` | String | | native select name |

| event | Description |
| -------- | ----------------------- |
| `@focus` | emitted on focus gained |
| `@blur` | emitted on focus lost |

### mdc-option

| props | Type | Default | Description |
| ---------- | ------- | ------- | ------------------------------- |
| `disabled` | Boolean | false | whether this option is disabled |
| `value` | String | | option value |

> If no option value is specified, the select component will take the option's textContent.
```html
<mdc-select v-model="selected" label=">Please select one">
<mdc-option value="a">A</mdc-option>
<mdc-option value="b">B</mdc-option>
<mdc-option value="c">C</mdc-option>
</mdc-select>
```

### Multiple select

```html
<mdc-select multiple v-model="selected" label="Please select one or more">
<mdc-option>A</mdc-option>
<mdc-option>B</mdc-option>
<mdc-option>C</mdc-option>
</mdc-select>
<span>Selected: {{ selected }}</span>
```

```javascript
var vm = new Vue({
data () {
return {
selected: [],
}
}
})
```

> multi-select are always rendered natively. the size is reactive and is caped
> by the max-size property
### Reference

- <https://material.io/components/web/catalog/input-controls/select-menus>
## Usage

```html
<mdc-select v-model="selected" label=">Please select one">
<mdc-option>A</mdc-option>
<mdc-option>B</mdc-option>
<mdc-option>C</mdc-option>
</mdc-select>
<span>Selected: {{ selected }}</span>
```

```javascript
var vm = new Vue({
data() {
return {
selected: '',
};
},
});
```

> For better cross-device experiennce, `<mdc-select>` will switch from menu to
> native rendering based on the media query
> `(max-width: 600px) and (pointer: coarse)`.
### mdc-select

| props | Type | Default | Description |
| ---------- | --------------- | ------- | -------------------------------------------- |
| `disabled` | Boolean | false | whether this select is disabled |
| `label` | String | | the selection label |
| `value` | [String, Array] | | bind with v-model (update on `change` event) |
| `max-size` | Boolean | 4 | multi select max size |
| `name` | String | | native select name |

| event | Description |
| -------- | ----------------------- |
| `@focus` | emitted on focus gained |
| `@blur` | emitted on focus lost |

### mdc-option

| props | Type | Default | Description |
| ---------- | ------- | ------- | ------------------------------- |
| `disabled` | Boolean | false | whether this option is disabled |
| `value` | String | | option value |

> If no option value is specified, the select component will take the option's textContent.
### mdc-optgroup

| props | Type | Default | Description |
| ---------- | ------- | ------- | ------------------------------- |
| `disabled` | Boolean | false | whether this option is disabled |
| `label` | String | | optgroup label |

```html
<mdc-select v-model="selected" label=">Please select one">
<mdc-optgroup label="Meats">
<mdc-option value="steak">Steak</mdc-option>
<mdc-option value="hamburger">Hamburger</mdc-option>
</mdc-optgroup>
<mdc-optgroup label="Vegetables">
<mdc-option value="beet">Beet</mdc-option>
<mdc-option value="carrot">Carrot</mdc-option>
</mdc-optgroup>
</mdc-select>
```

### Reference

* <https://material.io/components/web/catalog/input-controls/select-menus>
88 changes: 37 additions & 51 deletions components/select/demo.vue
Original file line number Diff line number Diff line change
@@ -1,56 +1,42 @@
<template>
<div class="mdc-demo mdc-demo--container">
<div>
<mdc-select v-model="selectedType" label="Pick up a food type">
<mdc-option v-for="type in types" :key="type"
>{{type}}</mdc-option>
</mdc-select>
<br><br><br>
<mdc-select box v-model="selectedValue" label="Pick up a food"
v-if="selectedType">
<mdc-option v-for="option of options" :key="option"
:value="option.toLowerCase()"
>{{option}}</mdc-option>
</mdc-select>
<template>
<div class="mdc-demo mdc-demo--container">
<div>
<mdc-select v-model="selectedType" label="Pick up a food type">
<mdc-option v-for="type in types" :key="type">{{type}}</mdc-option>
</mdc-select>
<br><br><br>
<mdc-select box v-model="selectedValue" label="Pick up a food" v-if="selectedType">
<mdc-option v-for="option of options" :key="option" :value="option.toLowerCase()">{{option}}</mdc-option>
</mdc-select>

<mdc-caption tag="p" v-if="selectedType"
>Selected Value: {{ selectedValue }}</mdc-caption>
<br>
<mdc-caption tag="p" v-if="selectedType">Selected Value: {{ selectedValue }}</mdc-caption>
<br>

<mdc-select multiple v-model="selectedValues" label="Pick one or more"
v-if="selectedType">
<mdc-option v-for="option of options" :key="option"
:value="option.toLowerCase()">
{{option}}
</mdc-option>
</mdc-select>
<mdc-caption tag="p" v-if="selectedType"
>Multi Select: {{ selectedValues }}</mdc-caption>
</div>
</div>
</div>
</template>

<script>
export default {
data () {
return {
selectedType: undefined,
selectedValue: undefined,
selectedValues: [],
food: {
'Vegetables' : ['Spinach', 'Carrots', 'Onions', 'Broccoli'],
'Meat' : [ 'Eggs', 'Chicken', 'Fish', 'Turkey', 'Pork' , 'Beef'],
'Fruits' : ['Apples', 'Oranges', 'Bananas', 'Berries', 'Lemons'],
}
}
},
computed: {
types () {
return Object.keys(this.food)
},
options () {
return this.selectedType ? this.food[this.selectedType] : []
}
}
}
</script>
<script>
export default {
data() {
return {
selectedType: undefined,
selectedValue: undefined,
selectedValues: [],
food: {
Vegetables: ['Spinach', 'Carrots', 'Onions', 'Broccoli'],
Meat: ['Eggs', 'Chicken', 'Fish', 'Turkey', 'Pork', 'Beef'],
Fruits: ['Apples', 'Oranges', 'Bananas', 'Berries', 'Lemons'],
},
};
},
computed: {
types() {
return Object.keys(this.food);
},
options() {
return this.selectedType ? this.food[this.selectedType] : [];
},
},
};
</script>
16 changes: 7 additions & 9 deletions components/select/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {BasePlugin} from '../base'
import mdcSelect from './mdc-select.vue'
import mdcOption from './mdc-option.vue'
import { BasePlugin } from '../base';
import mdcSelect from './mdc-select.vue';
import mdcOption from './mdc-option.vue';
import mdcOptgroup from './mdc-optgroup.vue';


export {
mdcSelect,
mdcOption,
}
export { mdcSelect, mdcOption, mdcOptgroup };

export default BasePlugin({
mdcSelect,
mdcOption,
})
mdcOptgroup,
});
19 changes: 0 additions & 19 deletions components/select/mdc-menu-option.vue

This file was deleted.

Loading

0 comments on commit 755ffac

Please sign in to comment.