Skip to content

Commit ae21768

Browse files
committed
feat: use nc input fields instead of bare fields
1 parent 08cfe08 commit ae21768

3 files changed

Lines changed: 53 additions & 25 deletions

File tree

src/components/HouseSettingsDialog/HouseSettingsDialog.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@
4545
<tr v-for="member in members" :key="member.id">
4646
<td>{{ member.displayName }}</td>
4747
<td>
48-
<select
48+
<NcSelect
4949
v-if="canAdmin && member.role !== 'owner'"
50-
:value="member.role"
51-
@change="changeRole(member.id, ($event.target as HTMLSelectElement).value)"
52-
>
53-
<option value="admin">{{ roleLabel('admin') }}</option>
54-
<option value="member">{{ roleLabel('member') }}</option>
55-
</select>
50+
:model-value="roleOptionFor(member.role)"
51+
:options="roleOptions"
52+
:clearable="false"
53+
:searchable="false"
54+
autocomplete="off"
55+
@option:selected="(opt: RoleOption) => changeRole(member.id, opt.value)"
56+
/>
5657
<span v-else>{{ roleLabel(member.role) }}</span>
5758
</td>
5859
<td>
@@ -154,7 +155,12 @@
154155
:placeholder="strings.userIdPlaceholder"
155156
autocomplete="off"
156157
/>
157-
<NcSelect v-model="newRoleOption" :options="roleOptions" :input-label="strings.roleLabel" />
158+
<NcSelect
159+
v-model="newRoleOption"
160+
:options="roleOptions"
161+
:input-label="strings.roleLabel"
162+
autocomplete="off"
163+
/>
158164
<p v-if="addError" class="pantry-form-error">{{ addError }}</p>
159165
</form>
160166
<template #actions>
@@ -562,6 +568,10 @@ function roleLabel(role: HouseRole): string {
562568
}
563569
}
564570
571+
function roleOptionFor(role: HouseRole): RoleOption {
572+
return roleOptions.value.find((o) => o.value === role) ?? roleOptions.value[0]!
573+
}
574+
565575
const strings = {
566576
title: t('pantry', 'House settings'),
567577
generalSection: t('pantry', 'General'),

src/components/RecurrenceEditor/RecurrenceEditor.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ vi.mock('@nextcloud/vue/components/NcCheckboxRadioSwitch', () => ({
3838
default: {
3939
name: 'NcCheckboxRadioSwitch',
4040
template:
41-
'<label class="nc-checkbox"><input type="checkbox" :checked="modelValue" @change="$emit(\'update:modelValue\', $event.target.checked)" /><slot /></label>',
42-
props: ['modelValue', 'type'],
41+
"<label :class=\"type === 'radio' ? 'nc-radio' : 'nc-checkbox'\"><input :type=\"type === 'radio' ? 'radio' : 'checkbox'\" :checked=\"type === 'radio' ? modelValue === value : !!modelValue\" :value=\"value\" :name=\"name\" @change=\"$emit('update:modelValue', type === 'radio' ? value : $event.target.checked)\" /><slot /></label>",
42+
props: ['modelValue', 'type', 'value', 'name'],
4343
emits: ['update:modelValue'],
4444
},
4545
}))
@@ -143,7 +143,7 @@ describe('RecurrenceEditor', () => {
143143

144144
it('renders end condition radio buttons', () => {
145145
const wrapper = mountEditor()
146-
const radios = wrapper.findAll('.pantry-recurrence__radio')
146+
const radios = wrapper.findAll('.nc-radio')
147147
expect(radios.length).toBe(3)
148148
})
149149

src/components/RecurrenceEditor/RecurrenceEditor.vue

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,25 @@
8787
<section class="pantry-recurrence__section">
8888
<label class="pantry-recurrence__label">{{ strings.endsLabel }}</label>
8989
<div class="pantry-recurrence__ends">
90-
<label class="pantry-recurrence__radio">
91-
<input v-model="endKind" type="radio" value="never" />
92-
<span>{{ strings.endNever }}</span>
93-
</label>
94-
<label class="pantry-recurrence__radio">
95-
<input v-model="endKind" type="radio" value="count" />
96-
<span>{{ strings.endAfter }}</span>
90+
<NcCheckboxRadioSwitch
91+
:model-value="endKind"
92+
value="never"
93+
name="pantry-end-kind"
94+
type="radio"
95+
@update:model-value="endKind = $event"
96+
>
97+
{{ strings.endNever }}
98+
</NcCheckboxRadioSwitch>
99+
<div class="pantry-recurrence__radio-row">
100+
<NcCheckboxRadioSwitch
101+
:model-value="endKind"
102+
value="count"
103+
name="pantry-end-kind"
104+
type="radio"
105+
@update:model-value="endKind = $event"
106+
>
107+
{{ strings.endAfter }}
108+
</NcCheckboxRadioSwitch>
97109
<input
98110
v-model.number="endCount"
99111
type="number"
@@ -103,17 +115,24 @@
103115
:disabled="endKind !== 'count'"
104116
/>
105117
<span>{{ strings.endAfterSuffix }}</span>
106-
</label>
107-
<label class="pantry-recurrence__radio">
108-
<input v-model="endKind" type="radio" value="until" />
109-
<span>{{ strings.endOn }}</span>
118+
</div>
119+
<div class="pantry-recurrence__radio-row">
120+
<NcCheckboxRadioSwitch
121+
:model-value="endKind"
122+
value="until"
123+
name="pantry-end-kind"
124+
type="radio"
125+
@update:model-value="endKind = $event"
126+
>
127+
{{ strings.endOn }}
128+
</NcCheckboxRadioSwitch>
110129
<input
111130
v-model="endUntil"
112131
type="date"
113132
class="pantry-recurrence__date"
114133
:disabled="endKind !== 'until'"
115134
/>
116-
</label>
135+
</div>
117136
</div>
118137
</section>
119138

@@ -610,11 +629,10 @@ const strings = {
610629
gap: 0.5rem;
611630
}
612631
613-
&__radio {
632+
&__radio-row {
614633
display: flex;
615634
align-items: center;
616635
gap: 0.5rem;
617-
cursor: pointer;
618636
}
619637
620638
&__divider {

0 commit comments

Comments
 (0)