Skip to content

Commit 2d840c2

Browse files
authored
Merge pull request #34 from tomoam/update-up-to-20230330
2023/03/30 迄の更新に追従
2 parents 84c6ee8 + 260460d commit 2d840c2

File tree

78 files changed

+470
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+470
-585
lines changed

content/tutorial/01-svelte/06-bindings/03-checkbox-inputs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ title: Checkbox inputs
66

77
```svelte
88
/// file: App.svelte
9-
<input type=checkbox bind:checked={yes}>
9+
<input type=checkbox +++bind:+++checked={yes}>
1010
```

content/tutorial/01-svelte/06-bindings/04-group-inputs/README.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

content/tutorial/01-svelte/06-bindings/04-group-inputs/app-a/src/lib/App.svelte

Lines changed: 0 additions & 54 deletions
This file was deleted.

content/tutorial/01-svelte/06-bindings/04-group-inputs/app-b/src/lib/App.svelte

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Select bindings
3+
---
4+
5+
`<select>` 要素にも `bind:value` を使用できます。
6+
7+
```svelte
8+
/// file: App.svelte
9+
<select
10+
+++bind:+++value={selected}
11+
on:change={() => answer = ''}
12+
>
13+
```
14+
15+
`<option>` の値は文字列ではなくオブジェクトであることにご注意ください。Svelteは気にしません。
16+
17+
> `selected` の初期値を設定していないので、バインディングは自動的にデフォルト値(配列の先頭)に設定されます。しかし、注意してください。バインディングが初期化されるまで、`selected` は undefined のままなので、よく考えもせずにテンプレート内の `selected.id` などを参照することはできません。
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Group inputs
3+
---
4+
5+
同じ値に関連している `type="radio"` input や `type="checkbox"` input が複数ある場合、`value` 属性とともに `bind:group` を使うことができます。同じグループの radio input は互いに排他的(exclusive)です。同じグループの checkbox input は選択した値の配列を構成します。
6+
7+
`bind:group={scoops}` を radio input に追加し…
8+
9+
```svelte
10+
/// file: App.svelte
11+
<input
12+
type="radio"
13+
name="scoops"
14+
value={number}
15+
+++bind:group={scoops}+++
16+
/>
17+
```
18+
19+
…そして `bind:group={flavours}` を checkbox input に追加します:
20+
21+
```svelte
22+
/// file: App.svelte
23+
<input
24+
type="checkbox"
25+
name="flavours"
26+
value={flavour}
27+
+++bind:group={flavours}+++
28+
/>
29+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<script>
2+
let scoops = 1;
3+
let flavours = [];
4+
5+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
6+
</script>
7+
8+
<h2>Size</h2>
9+
10+
{#each [1, 2, 3] as number}
11+
<label>
12+
<input
13+
type="radio"
14+
name="scoops"
15+
value={number}
16+
/>
17+
18+
{number} {number === 1 ? 'scoop' : 'scoops'}
19+
</label>
20+
{/each}
21+
22+
<h2>Flavours</h2>
23+
24+
{#each ['cookies and cream', 'mint choc chip', 'raspberry ripple'] as flavour}
25+
<label>
26+
<input
27+
type="checkbox"
28+
name="flavours"
29+
value={flavour}
30+
/>
31+
32+
{flavour}
33+
</label>
34+
{/each}
35+
36+
{#if flavours.length === 0}
37+
<p>Please select at least one flavour</p>
38+
{:else if flavours.length > scoops}
39+
<p>Can't order more flavours than scoops!</p>
40+
{:else}
41+
<p>
42+
You ordered {scoops} {scoops === 1 ? 'scoop' : 'scoops'}
43+
of {formatter.format(flavours)}
44+
</p>
45+
{/if}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script>
2+
let scoops = 1;
3+
let flavours = [];
4+
5+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
6+
</script>
7+
8+
<h2>Size</h2>
9+
10+
{#each [1, 2, 3] as number}
11+
<label>
12+
<input
13+
type="radio"
14+
name="scoops"
15+
value={number}
16+
bind:group={scoops}
17+
/>
18+
19+
{number} {number === 1 ? 'scoop' : 'scoops'}
20+
</label>
21+
{/each}
22+
23+
<h2>Flavours</h2>
24+
25+
{#each ['cookies and cream', 'mint choc chip', 'raspberry ripple'] as flavour}
26+
<label>
27+
<input
28+
type="checkbox"
29+
name="flavours"
30+
value={flavour}
31+
bind:group={flavours}
32+
/>
33+
34+
{flavour}
35+
</label>
36+
{/each}
37+
38+
{#if flavours.length === 0}
39+
<p>Please select at least one flavour</p>
40+
{:else if flavours.length > scoops}
41+
<p>Can't order more flavours than scoops!</p>
42+
{:else}
43+
<p>
44+
You ordered {scoops} {scoops === 1 ? 'scoop' : 'scoops'}
45+
of {formatter.format(flavours)}
46+
</p>
47+
{/if}

0 commit comments

Comments
 (0)