Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit e972217

Browse files
fixes table example + related combobox bug + adds test
1 parent acfbc9a commit e972217

File tree

3 files changed

+75
-27
lines changed

3 files changed

+75
-27
lines changed

src/components/Combobox/Combobox.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { mixins } from 'vue-class-component';
22
import { UidMixin } from '@/mixins';
3-
import { Popover } from '@/components/Popover';
4-
import { Button } from '@/components/Button';
5-
import { Input, InputGroup } from '@/components/Form';
3+
import { MenuItem, Button, Popover, Input, InputGroup } from '@/components';
64
import { Component, Event, Prop } from '@/core';
75

86
interface Props {
@@ -41,14 +39,14 @@ export class Combobox extends mixins(UidMixin) {
4139
public $tsxProps!: Readonly<{}> & Readonly<Props>;
4240

4341
private currentPopoverVisible: boolean = this.popoverVisible;
44-
private currentValue: string | null = this.value;
42+
private currentValue: string | number | null = this.value;
4543

4644
public togglePopoverVisible() {
4745
this.currentPopoverVisible = !this.currentPopoverVisible;
4846
this.$emit('update:currentPopoverVisible', this.currentPopoverVisible);
4947
}
5048

51-
private setCurrentValue(newValue: string | null) {
49+
private setCurrentValue(newValue: string | number | null) {
5250
this.currentValue = newValue;
5351
this.$emit('input', this.currentValue);
5452
this.$emit('update:value', this.currentValue);
@@ -63,13 +61,24 @@ export class Combobox extends mixins(UidMixin) {
6361
}
6462
}
6563

64+
private handleMenuItemClick(item: MenuItem) {
65+
this.setCurrentValue(item.value);
66+
}
67+
6668
public render() {
6769
const dropdown = this.$slots.default;
6870
return (
6971
<div class='fd-combobox-input'>
70-
<Popover noArrow={true} popoverVisible={this.currentPopoverVisible}>
72+
<Popover
73+
on-click={this.handleMenuItemClick}
74+
noArrow={true}
75+
popoverVisible={this.currentPopoverVisible}
76+
>
7177
<div class='fd-combobox-control' slot='control'>
72-
<InputGroup compact={this.compact} afterClass={'fd-input-group__addon--button'}>
78+
<InputGroup
79+
compact={this.compact}
80+
afterClass='fd-input-group__addon--button'
81+
>
7382
<Input
7483
id={this.uid}
7584
value={this.value}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { assert } from 'chai';
2+
import { mount } from '@vue/test-utils';
3+
import { Combobox } from './../';
4+
import { MenuItem } from './../../Menu';
5+
6+
describe('Combobox', () => {
7+
it('supports vmodel', () => {
8+
const wrapper = mount({
9+
template: `
10+
<Combobox v-model="value">
11+
<MenuItem ref="menuItem1" value='1'>1</MenuItem>
12+
<MenuItem value='2'>2</MenuItem>
13+
<MenuItem value='3'>3</MenuItem>
14+
<MenuItem value='4'>4</MenuItem>
15+
</Combobox>
16+
`,
17+
data() {
18+
return {
19+
value: 'abc',
20+
};
21+
},
22+
components: {
23+
Combobox,
24+
MenuItem,
25+
},
26+
});
27+
const item = wrapper.find({ ref: 'menuItem1' });
28+
item.find('a').trigger('click');
29+
assert.strictEqual(item.text(), '1'); // ensure that we have selected the correct item
30+
// @ts-ignore
31+
assert.strictEqual(wrapper.vm.value, '1');
32+
});
33+
});

src/docs/pages/Table/1-complex.vue

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@
88
<FdTableColumn sortable prop="lastName" label="Last Name" />
99
<FdTableColumn label="Initials">
1010
<template slot-scope="scope">
11-
<span style="margin-left: 10px">{{ scope.row.firstName }}_{{ scope.row.lastName }}</span>
11+
<span style="margin-left: 10px">
12+
{{ scope.row.firstName }}_{{ scope.row.lastName }}
13+
</span>
1214
</template>
1315
</FdTableColumn>
1416
</FdTable>
1517
<FdFormSet>
16-
<FdFormItem>
17-
<FdFormLabel>First Name</FdFormLabel>
18+
<FdFormItem label="First Name">
1819
<FdInput v-model="newEntry.firstName" placeholder="Enter something nice"/>
1920
</FdFormItem>
20-
<FdFormItem>
21-
<FdFormLabel>Last Name</FdFormLabel>
21+
<FdFormItem label="Last Name">
2222
<FdInput v-model="newEntry.lastName" placeholder="Enter something nice"/>
2323
</FdFormItem>
24-
<FdFormItem>
25-
<FdFormLabel>Rating</FdFormLabel>
24+
<FdFormItem label="Rating">
2625
<FdCombobox v-model="newEntry.rating">
27-
<FdMenuItem value="1" title="1">1</FdMenuItem>
28-
<FdMenuItem value="2" title="2">2</FdMenuItem>
29-
<FdMenuItem value="3" title="3">3</FdMenuItem>
30-
<FdMenuItem value="4" title="4">4</FdMenuItem>
31-
<FdMenuItem value="4" title="5">5</FdMenuItem>
26+
<FdMenuItem value="1">1</FdMenuItem>
27+
<FdMenuItem value="2">2</FdMenuItem>
28+
<FdMenuItem value="3">3</FdMenuItem>
29+
<FdMenuItem value="4">4</FdMenuItem>
30+
<FdMenuItem value="5">5</FdMenuItem>
3231
</FdCombobox>
3332
</FdFormItem>
3433
</FdFormSet>
@@ -40,24 +39,31 @@
4039
export default {
4140
methods: {
4241
addCurrentEntry() {
43-
const tableEntry = { ...this.newEntry, building: null, rating: this.newEntry.rating.value };
44-
this.tableData.push(tableEntry);
42+
const entry = {
43+
...this.newEntry,
44+
};
45+
this.tableData = [...this.tableData, entry];
46+
this.newEntry = {
47+
firstName: null,
48+
lastName: null,
49+
rating: "1"
50+
};
4551
},
4652
},
4753
data() {
4854
return {
4955
newEntry: {
5056
firstName: null,
5157
lastName: null,
52-
rating: '1',
58+
rating: "1",
5359
},
5460
tableData: [
55-
{ rating: 1, firstName: 'Chris', lastName: 'Kienle', building: 'WFD02' },
56-
{ rating: 2, firstName: 'Andi', lastName: 'Kienle', building: 'WFD03' },
57-
{ rating: 3, firstName: 'Sven', lastName: 'Bacia', building: 'WFD02' },
58-
{ rating: 4, firstName: 'Artur', lastName: 'Raess', building: 'WFD02' },
61+
{ rating: 1, firstName: "Chris", lastName: "Kienle" },
62+
{ rating: 2, firstName: "Andi", lastName: "Kienle" },
63+
{ rating: 3, firstName: "Sven", lastName: "Bacia" },
64+
{ rating: 4, firstName: "Artur", lastName: "Raess" },
5965
],
6066
};
6167
},
6268
};
63-
</script>
69+
</script>

0 commit comments

Comments
 (0)