mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 04:13:02 +00:00
test: assert read-only arrays
This commit is contained in:
parent
eedc619900
commit
06f96638e5
4 changed files with 53 additions and 12 deletions
|
@ -9,13 +9,16 @@
|
||||||
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
|
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
|
||||||
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
|
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
|
||||||
|
|
||||||
|
let ref: HTMLElement;
|
||||||
let selectedId = "0";
|
let selectedId = "0";
|
||||||
let selectedIds = [];
|
let selectedIds = [];
|
||||||
|
|
||||||
$: console.log("selectedId", selectedId);
|
$: console.log("selectedId", selectedId);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ContextMenu open on:open="{(e) => console.log(e.detail)}">
|
<div bind:this="{ref}"></div>
|
||||||
|
|
||||||
|
<ContextMenu target="{null}" open on:open="{(e) => console.log(e.detail)}">
|
||||||
<ContextMenuOption
|
<ContextMenuOption
|
||||||
kind="danger"
|
kind="danger"
|
||||||
indented
|
indented
|
||||||
|
@ -42,7 +45,7 @@
|
||||||
</ContextMenuGroup>
|
</ContextMenuGroup>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
|
|
||||||
<ContextMenu on:open on:close>
|
<ContextMenu target="{[null, ref]}" on:open on:close>
|
||||||
<ContextMenuOption indented labelText="Open" />
|
<ContextMenuOption indented labelText="Open" />
|
||||||
<ContextMenuDivider />
|
<ContextMenuDivider />
|
||||||
<ContextMenuRadioGroup bind:selectedId labelText="Radio group">
|
<ContextMenuRadioGroup bind:selectedId labelText="Radio group">
|
||||||
|
|
|
@ -1,16 +1,41 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Dropdown, DropdownSkeleton } from "../types";
|
import { Dropdown, DropdownSkeleton } from "../types";
|
||||||
|
import type { DropdownProps } from "../types/Dropdown/Dropdown.svelte";
|
||||||
|
|
||||||
|
let items: DropdownProps["items"] = [
|
||||||
|
{ id: 0, text: "Slack" },
|
||||||
|
{ id: "1", text: "Email" },
|
||||||
|
{ id: "2", text: "Fax" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
let itemsWithoutConst = [...items];
|
||||||
|
|
||||||
|
type FieldId = typeof items[number]["id"]; // 'foo' | 'bar' | 'baz'
|
||||||
|
|
||||||
|
export const fieldId: FieldId = "bar";
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
$: items[0] = { id: "0", text: "Slack" };
|
||||||
|
$: {
|
||||||
|
// @ts-expect-error
|
||||||
|
items[0] = { id: "0", text: "Slack" };
|
||||||
|
}
|
||||||
|
$: {
|
||||||
|
items = [...items, { id: "3", text: "Email" }];
|
||||||
|
items = items.map((item, index) => {
|
||||||
|
if (index === 0) {
|
||||||
|
return { id: "0", text: "Slack" };
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
direction="top"
|
direction="top"
|
||||||
titleText="Contact"
|
titleText="Contact"
|
||||||
selectedId="0"
|
selectedId="0"
|
||||||
items="{[
|
items="{items}"
|
||||||
{ id: 0, text: 'Slack' },
|
|
||||||
{ id: '1', text: 'Email' },
|
|
||||||
{ id: '2', text: 'Fax', disabled: true },
|
|
||||||
]}"
|
|
||||||
on:select="{(e) => {
|
on:select="{(e) => {
|
||||||
console.log(e.detail.selectedId);
|
console.log(e.detail.selectedId);
|
||||||
}}"
|
}}"
|
||||||
|
@ -31,11 +56,7 @@
|
||||||
}}"
|
}}"
|
||||||
titleText="Contact"
|
titleText="Contact"
|
||||||
selectedId="0"
|
selectedId="0"
|
||||||
items="{[
|
items="{itemsWithoutConst}"
|
||||||
{ id: '0', text: 'Slack' },
|
|
||||||
{ id: '1', text: 'Email' },
|
|
||||||
{ id: '2', text: 'Fax' },
|
|
||||||
]}"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
|
|
@ -6,8 +6,15 @@
|
||||||
FileUploaderItem,
|
FileUploaderItem,
|
||||||
FileUploaderSkeleton,
|
FileUploaderSkeleton,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
|
import type { FileUploaderProps } from "../types/FileUploader/FileUploader.svelte";
|
||||||
|
|
||||||
let fileUploader: FileUploader;
|
let fileUploader: FileUploader;
|
||||||
|
let files: FileUploaderProps["files"] = [];
|
||||||
|
|
||||||
|
$: {
|
||||||
|
// @ts-expect-error
|
||||||
|
files[0] = null;
|
||||||
|
}
|
||||||
|
|
||||||
$: fileUploader?.clearFiles();
|
$: fileUploader?.clearFiles();
|
||||||
</script>
|
</script>
|
||||||
|
@ -27,6 +34,7 @@
|
||||||
labelDescription="Only JPEG files are accepted."
|
labelDescription="Only JPEG files are accepted."
|
||||||
accept="{['.jpg', '.jpeg']}"
|
accept="{['.jpg', '.jpeg']}"
|
||||||
status="complete"
|
status="complete"
|
||||||
|
bind:files
|
||||||
on:add="{(e) => {
|
on:add="{(e) => {
|
||||||
console.log(e.detail); // File[]
|
console.log(e.detail); // File[]
|
||||||
}}"
|
}}"
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MultiSelect } from "../types";
|
import { MultiSelect } from "../types";
|
||||||
|
import type { MultiSelectProps } from "../types/MultiSelect/MultiSelect.svelte";
|
||||||
|
|
||||||
|
let selectedIds: MultiSelectProps["selectedIds"] = [0];
|
||||||
|
|
||||||
|
$: {
|
||||||
|
// @ts-expect-error
|
||||||
|
selectedIds[0] = [0];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
|
@ -7,6 +15,7 @@
|
||||||
titleText="Contact"
|
titleText="Contact"
|
||||||
label="Select contact methods..."
|
label="Select contact methods..."
|
||||||
hideLabel
|
hideLabel
|
||||||
|
bind:selectedIds
|
||||||
items="{[
|
items="{[
|
||||||
{ id: 0, text: 'Slack' },
|
{ id: 0, text: 'Slack' },
|
||||||
{ id: '1', text: 'Email' },
|
{ id: '1', text: 'Email' },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue