Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make KRadioButton to show a warning for developers when it's not nested inside KRadioButtonGroup #781

Merged
merged 13 commits into from
Sep 17, 2024
15 changes: 15 additions & 0 deletions lib/KRadioButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
"KRadioButton: 'value' prop is deprecated and will be removed in a future release. Please use 'buttonValue' instead."
);
}
if (process.env.NODE_ENV !== 'production') {
this.checkForKRadioButtonGroup();
}
},
methods: {
/**
Expand Down Expand Up @@ -237,6 +240,18 @@
setTabIndex(val) {
this.tabIndex = val;
},

checkForKRadioButtonGroup() {
let parent = this.$parent;
while (parent) {
if (parent.$options.name === 'KRadioButtonGroup') {
return; // Found KRadioButtonGroup, no warning needed
}
parent = parent.$parent;
}
// If we get here, no KRadioButtonGroup was found
console.warn('KRadioButton should be nested inside a KRadioButtonGroup component.');
},
},
};

Expand Down