Skip to content

Commit 86d1629

Browse files
authored
Merge pull request #8126 from nextcloud-libraries/backport/8118/stable8
[stable8] feat(NcRadioGroupButton): add disabled state styling to NcRadioGroupButton
2 parents 10db37c + 9d78adc commit 86d1629

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ module.exports = {
6464
'/node_modules/(?!(' + ignorePatterns.join('|') + '))',
6565
],
6666

67+
globals: {
68+
'vue-jest': {
69+
resources: {
70+
scss: ['src/assets/variables.scss'],
71+
},
72+
},
73+
},
74+
6775
moduleNameMapper: {
6876
'\\.(css|scss)$': 'jest-transform-stub',
6977
'\\?raw$': 'jest-raw-loader',

src/components/NcRadioGroup/NcRadioGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The radio group also allows to create a button like styling together with the `N
166166
<h4>With icons</h4>
167167
<div style="max-width: 250px">
168168
<NcRadioGroup v-model="alignment" label="Example alignment with icons" hide-label>
169-
<NcRadioGroupButton aria-label="Start" value="start">
169+
<NcRadioGroupButton aria-label="Start" value="start" disabled>
170170
<template #icon>
171171
<NcIconSvgWrapper directional :path="mdiAlignHorizontalLeft" />
172172
</template>

src/components/NcRadioGroupButton/NcRadioGroupButton.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const props = defineProps<{
2424
* The value that should be assigned to the `modelValue` of the `NcRadioGroup`.
2525
*/
2626
value: string
27+
28+
/**
29+
* Disabled state of the radio button
30+
*/
31+
disabled?: boolean
2732
}>()
2833
2934
const labelId = createElementId()
@@ -38,6 +43,10 @@ const isChecked = computed(() => radioGroup?.value.modelValue === props.value)
3843
* Handle updating the current model value
3944
*/
4045
function onUpdate() {
46+
if (props.disabled) {
47+
return
48+
}
49+
4150
radioGroup!.value.onUpdate(props.value)
4251
}
4352
</script>
@@ -46,6 +55,7 @@ function onUpdate() {
4655
<div
4756
:class="[{
4857
[$style.radioGroupButton_active]: isChecked,
58+
[$style.radioGroupButton_disabled]: disabled,
4959
}, $style.radioGroupButton, formBoxItemClass]"
5060
@click="onUpdate">
5161
<div v-if="$scopedSlots.icon" :class="$style.radioGroupButton__icon">
@@ -63,6 +73,7 @@ function onUpdate() {
6373
class="hidden-visually"
6474
:checked="isChecked"
6575
type="radio"
76+
:disabled="disabled"
6677
:value="value"
6778
@input="onUpdate">
6879
</div>
@@ -105,7 +116,7 @@ function onUpdate() {
105116
padding-inline-start: var(--radio-group-button--padding);
106117
}
107118
108-
&:hover {
119+
&:hover:not(.radioGroupButton_disabled) {
109120
background-color: var(--radio-group-button--background-color-hover);
110121
}
111122
@@ -127,6 +138,17 @@ function onUpdate() {
127138
font-weight: bold;
128139
}
129140
141+
.radioGroupButton_disabled {
142+
filter: saturate($opacity_normal);
143+
opacity: $opacity_disabled;
144+
145+
// Reset the cursor
146+
cursor: default;
147+
* {
148+
cursor: default;
149+
}
150+
}
151+
130152
.radioGroupButton__icon {
131153
--radio-group-button--icon-size: calc(var(--default-clickable-area) - 4px);
132154
display: flex;

0 commit comments

Comments
 (0)