diff --git a/TEMP-MIGRATION-CHANGELOG.md b/TEMP-MIGRATION-CHANGELOG.md index 94c4a122bf..b49d87f43e 100644 --- a/TEMP-MIGRATION-CHANGELOG.md +++ b/TEMP-MIGRATION-CHANGELOG.md @@ -49,6 +49,25 @@ export default defineConfig({ - `v-model` is now mapped to `modelValue` prop, and emits `input` and `update:modelValue` events. +### KTextArea + +- `v-model` is now mapped to `modelValue` prop, and emits `input`, `update:modelValue`, `char-limit-exceeded` events. + +### KCheckbox + +- `v-model` is now mapped to `modelValue` prop, and emits `input`, `change`, and `update:modelValue` events. + +### KRadio + +- `v-model` is now mapped to `modelValue` prop, and emits `change`, and `update:modelValue` events. +- `value` prop has been renamed to `selectedValue` + +### KSelect + +- `v-model` is now mapped to `modelValue` prop, and emits `input`, `change`, and `update:modelValue` events. +- `positionFixed` now defaults to `true` +- TODO: Noticing a weird page scroll when clicking on the select item + ### KBreadcrumbs - `Kcrumbs` component is now `KBreadcrumbs` @@ -66,10 +85,5 @@ export default defineConfig({ - `Kooltip` component is now `KTooltip` -### KSelect - -- `positionFixed` now defaults to `true` -- TODO: Noticing a weird page scroll when clicking on the select item - ### KSkeleton - Renamed internal component from `Skeleton` to `SkeletonBase` diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index 98aa5174ec..bcdb19079c 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -95,6 +95,7 @@ export default defineUserConfig({ '/components/modal', '/components/pagination', '/components/popover', + '/components/radio', '/components/select', '/components/skeleton', '/components/table', diff --git a/docs/components/radio.md b/docs/components/radio.md new file mode 100644 index 0000000000..ad36d98a9f --- /dev/null +++ b/docs/components/radio.md @@ -0,0 +1,153 @@ +# Radio + +**KRadio** - KRadio is a wrapper around a Kong styled radio input. + + + + + +```vue + + + +``` + +## Props + +### v-model - required + +Use `v-model` to bind the `checked` state of the underlying ``. The `v-model` binds to the `modelValue` prop of the component and sets the current checked state of the input. You can read more about passing values via `v-model` [here](https://vuejs.org/guide/components/events.html#usage-with-v-model). + +### selectedValue + +The value of the `KRadio` option that will be emitted by the `change` and `update:modelValue` events. + +### HTML attributes + +Any valid attribute will be added to the input. You can read more about `$attrs` [here](https://vuejs.org/api/composition-api-setup.html#setup-context). + +```vue +Disabled radio +``` + + + + + +## Slots + +- `default` - Anything passed in to the default slot will replace the label prop text + + + + + +```vue + + Label goes here. The radio is {{ selected ? 'selected' : 'not selected' }} + +``` + +## Events + +`KCheckbox` has a couple of natural event bindings that all emit the same data when a radio option is selected. + +- `change` - Fired on change, returns the checked status of the checkbox. +- `update:modelValue` - Fired on change, returns the checked status of the checkbox. + +## Theming + +| Variable | Purpose +|:-------- |:------- +| `--KRadioPrimary`| Radio primary background & border color +| `--KRadioDisabled`| Radio disabled background color + +An Example of changing the background color of KRadio to mediumpurple might look like: + +> Note: We are scoping the overrides to a wrapper in this example + +
+ +
+ +```vue + + + +``` + + + + diff --git a/src/components/KRadio/KRadio.spec.ts b/src/components/KRadio/KRadio.spec.ts new file mode 100644 index 0000000000..c8f9e61694 --- /dev/null +++ b/src/components/KRadio/KRadio.spec.ts @@ -0,0 +1,43 @@ +// Import types for custom commands +/// + +import { mount } from '@cypress/vue' +import KRadio from '@/components/KRadio/KRadio.vue' + +describe('KRadio', () => { + it('shows as not selected when modelValue is true', () => { + mount(KRadio, { + props: { + modelValue: false, + selectedValue: true, + }, + }) + + cy.get('input').should('not.be.checked') + }) + + it('shows as selected when modelValue is true', () => { + mount(KRadio, { + props: { + modelValue: true, + selectedValue: true, + }, + }) + + cy.get('input').should('be.checked') + }) + + it('emits checked value on click', () => { + mount(KRadio, { + props: { + modelValue: false, + selectedValue: true, + }, + }) + + cy.get('input').check().then(() => { + cy.wrap(Cypress.vueWrapper.emitted()).should('have.property', 'change') + cy.wrap(Cypress.vueWrapper.emitted()).should('have.property', 'update:modelValue') + }) + }) +}) diff --git a/src/components/KRadio/KRadio.vue b/src/components/KRadio/KRadio.vue new file mode 100644 index 0000000000..f2dfc9e28d --- /dev/null +++ b/src/components/KRadio/KRadio.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/src/components/index.ts b/src/components/index.ts index 9fedabb82b..c541b8ce07 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -31,3 +31,4 @@ export { default as KTable } from './KTable/KTable.vue' export { default as KTextArea } from './KTextArea/KTextArea.vue' export { default as KCheckbox } from './KCheckbox/KCheckbox.vue' export { default as KInlineEdit } from './KInlineEdit/KInlineEdit.vue' +export { default as KRadio } from './KRadio/KRadio.vue'