Skip to content

Commit

Permalink
Make KRadioButton to show a warning for developers when it's not nest…
Browse files Browse the repository at this point in the history
…ed inside KRadioButtonGroup (#781)
  • Loading branch information
lokesh-sagi125 authored Sep 17, 2024
1 parent d84f302 commit 930e720
Showing 1 changed file with 15 additions and 0 deletions.
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

0 comments on commit 930e720

Please sign in to comment.