Skip to content

Commit

Permalink
fix(core/select): prevent string to be spread by '...' operator (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux authored Nov 23, 2022
1 parent 108e892 commit ec6744a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
*/

import {
Component,
Element,
Event,
EventEmitter,
h,
Host,
Listen,
Prop,
State,
Watch
Component,
Element,
Event,
EventEmitter,
h,
Host,
Listen,
Prop,
State,
Watch,
} from '@stencil/core';

@Component({
Expand Down Expand Up @@ -124,9 +124,17 @@ export class Select {

@Watch('selectedIndices')
watchSelectedIndices(newId: string | string[]) {
if (newId) {
if (!newId) {
this.selectValue([]);
return;
}

if (Array.isArray(newId)) {
this.selectValue([...newId]);
return;
}

this.selectValue([newId]);
}

@Listen('itemClick')
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/components/select/test/cw-select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ describe('ix-select', () => {
`);
});

it('show add item button in list', async () => {
const page = await newSpecPage({
components: [Select, SelectItem],
html: `<ix-select>
<ix-select-item data-testid="select-1" value="11" label="Item 1"></ix-select-item>
<ix-select-item data-testid="select-1" value="22" label="Item 2"></ix-select-item>
</ix-select>`,
});

await page.waitForChanges();

const selectElement = page.doc.querySelector('ix-select');

selectElement.selectedIndices = '22';
await page.waitForChanges();

expect(
(screen.getByTestId('input') as HTMLInputElement).value
).toStrictEqual('Item 2');
});

it('show add item button in list', async () => {
const page = await newSpecPage({
components: [Select],
Expand Down

0 comments on commit ec6744a

Please sign in to comment.