Merge pull request 'Fix(settings): selection reactivity' (#184) from fix/selection-setting-reactivity into main
Deploy on dev / Deploy on dev (push) Successful in 38s

Reviewed-on: #184
Reviewed-by: Jakob Gregory
This commit was merged in pull request #184.
This commit is contained in:
2026-08-06 23:41:53 +02:00
committed by Gitea
2 changed files with 29 additions and 4 deletions
@@ -54,10 +54,9 @@ const props = defineProps({
const store = useSettingsStore(); const store = useSettingsStore();
const optionType = computed(() => props.setting.allowMultiple ? 'checkbox' : 'radio'); const optionType = computed(() => props.setting.allowMultiple ? 'checkbox' : 'radio');
const selected = ref(normalizeSelectedValue(store.get(props.path) ?? props.setting.default)); const selected = computed({
get: () => normalizeSelectedValue(store.get(props.path) ?? props.setting.default),
watch(selected, (newValue) => { set: (value) => store.set(props.path, value)
store.set(props.path, newValue);
}); });
const labelId = useId(); const labelId = useId();
@@ -90,6 +90,32 @@ describe('Selection', () => {
expect(inputsChecked).toStrictEqual([false, true, false]); expect(inputsChecked).toStrictEqual([false, true, false]);
}); });
test('reacts on store change', async () => {
const wrapper = getWrapper({
options: exampleOptions,
piniaOptions: {
setupStores: () => {
const store = useSettingsStore();
store.set('selection', 'o1');
}
}
});
const settings = useSettingsStore();
{
const inputs = wrapper.findAll('input');
const inputsChecked = getChecked(inputs);
expect(inputsChecked).toStrictEqual([false, true, false]);
}
{
settings.set('selection', 'o2');
await nextTick();
const inputs = wrapper.findAll('input');
const inputsChecked = getChecked(inputs);
expect(inputsChecked).toStrictEqual([false, false, true]);
}
});
test('shows multiple values from store', () => { test('shows multiple values from store', () => {
const wrapper = getWrapper({ const wrapper = getWrapper({
options: exampleOptions, options: exampleOptions,