Skip to content

Commit 188fb84

Browse files
committed
fix(NcRadioGroup): re-implement using NcFieldset and NcFormGroup
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
1 parent 340c497 commit 188fb84

File tree

2 files changed

+18
-65
lines changed

2 files changed

+18
-65
lines changed

src/components/NcRadioGroup/NcRadioGroup.vue

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import type { Slot } from 'vue'
88
99
import { computed, provide, ref, warn } from 'vue'
10-
import { createElementId } from '../../utils/createElementId.ts'
10+
import NcFormBox from '../NcFormBox/NcFormBox.vue'
11+
import NcFormGroup from '../NcFormGroup/NcFormGroup.vue'
1112
import { INSIDE_RADIO_GROUP_KEY } from './useNcRadioGroup.ts'
1213
1314
const modelValue = defineModel<string>({ required: false, default: '' })
@@ -40,7 +41,6 @@ defineSlots<{
4041
default?: Slot
4142
}>()
4243
43-
const descriptionId = createElementId()
4444
const buttonVariant = ref<boolean>()
4545
4646
provide(INSIDE_RADIO_GROUP_KEY, computed(() => ({
@@ -72,62 +72,22 @@ function onUpdate(value: string) {
7272
</script>
7373

7474
<template>
75-
<fieldset
76-
:aria-describedby="description ? descriptionId : undefined"
77-
:class="[{
78-
[$style.radioGroup_buttonVariant]: buttonVariant,
79-
}, $style.radioGroup]">
80-
<legend :class="[$style.radioGroup__label, { 'hidden-visually': labelHidden }]">
81-
{{ label }}
82-
</legend>
83-
<p v-if="description" :id="descriptionId" :class="$style.radioGroup__description">
84-
{{ description }}
85-
</p>
86-
<div :class="$style.radioGroup__wrapper">
75+
<NcFormGroup
76+
:label
77+
:description
78+
:hide-label="labelHidden">
79+
<NcFormBox v-if="buttonVariant" row>
8780
<slot />
88-
</div>
89-
</fieldset>
81+
</NcFormBox>
82+
<span v-else :class="$style.radioGroup_checkboxRadioContainer">
83+
<slot />
84+
</span>
85+
</NcFormGroup>
9086
</template>
9187

9288
<style module lang="scss">
93-
.radioGroup {
94-
display: flex;
95-
flex-direction: column;
96-
97-
&:not(.radioGroup_buttonVariant) :global(.checkbox-content) {
98-
max-width: unset !important;
99-
}
100-
}
101-
102-
.radioGroup__label {
103-
font-size: 1.2em;
104-
font-weight: bold;
105-
margin-inline-start: var(--border-radius-element);
106-
}
107-
108-
.radioGroup__description {
109-
color: var(--color-text-maxcontrast);
110-
margin-block-end: var(--default-grid-baseline);
111-
margin-inline-start: var(--border-radius-element);
112-
}
113-
114-
.radioGroup__wrapper {
115-
display: flex;
116-
flex-direction: column;
117-
118-
> * {
119-
flex: 1 0 1px;
120-
}
121-
}
122-
123-
.radioGroup__label + .radioGroup__wrapper {
124-
// when there is no description we need to add some margin between wrapper and label
125-
margin-block-start: var(--default-grid-baseline);
126-
}
127-
128-
.radioGroup_buttonVariant .radioGroup__wrapper {
129-
flex-direction: row;
130-
gap: var(--default-grid-baseline);
89+
.radioGroup_checkboxRadioContainer :global(.checkbox-content) {
90+
max-width: unset !important;
13191
}
13292
</style>
13393

src/components/NcRadioGroupButton/NcRadioGroupButton.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Slot } from 'vue'
88
99
import { computed, onMounted } from 'vue'
1010
import { createElementId } from '../../utils/createElementId.ts'
11+
import { useNcFormBox } from '../NcFormBox/useNcFormBox.ts'
1112
import { useInsideRadioGroup } from '../NcRadioGroup/useNcRadioGroup.ts'
1213
1314
const props = defineProps<{
@@ -36,6 +37,8 @@ defineSlots<{
3637
3738
const labelId = createElementId()
3839
const radioGroup = useInsideRadioGroup()
40+
const { formBoxItemClass } = useNcFormBox()
41+
3942
onMounted(() => radioGroup!.value.register(true))
4043
4144
const isChecked = computed(() => radioGroup?.value.modelValue === props.value)
@@ -52,7 +55,7 @@ function onUpdate() {
5255
<div
5356
:class="[{
5457
[$style.radioGroupButton_active]: isChecked,
55-
}, $style.radioGroupButton]"
58+
}, $style.radioGroupButton, formBoxItemClass]"
5659
@click="onUpdate">
5760
<div v-if="$slots.icon" :class="$style.radioGroupButton__icon">
5861
<slot name="icon" />
@@ -120,16 +123,6 @@ function onUpdate() {
120123
border: var(--radio-group-button--border-width) solid var(--color-main-text) !important;
121124
outline: calc(var(--default-grid-baseline) / 2) var(--color-main-background);
122125
}
123-
124-
&:first-of-type {
125-
border-start-start-radius: var(--border-radius-element);
126-
border-end-start-radius: var(--border-radius-element);
127-
}
128-
129-
&:last-of-type {
130-
border-start-end-radius: var(--border-radius-element);
131-
border-end-end-radius: var(--border-radius-element);
132-
}
133126
}
134127
135128
.radioGroupButton_active {

0 commit comments

Comments
 (0)