Skip to content

Commit 7831557

Browse files
committed
feat(Radio): auto generate a unique id for label and input if none is specified and the input is not wrapped in a label
1 parent 1208297 commit 7831557

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

apps/docs/src/stories/Components/Radio.story.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
<story-canvas title="With description and body">
4444
<pf-radio
45-
id="radio3"
4645
name="radio-with-description-and-body"
4746
label="Radio with description and body"
4847
description="Single-tenant cloud service hosted and managed by Red Hat that offers high-availability enterprise-grade clusters in a virtual private cloud on AWS or GCP."

packages/core/src/components/Radio.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
:class="[styles.radioLabel, {
1616
[styles.modifiers.disabled]: disabled,
1717
}]"
18-
:for="wrapWithLabel ? undefined : id"
18+
:for="wrapWithLabel ? undefined : validId"
1919
>
2020
<slot name="label">{{ label }}</slot>
2121
</component>
2222
</sort-by>
2323

2424
<input
25-
:id="id"
25+
:id="wrapWithLabel ? id : validId"
2626
ref="input"
2727
v-bind="$attrs"
2828
type="radio"
@@ -53,6 +53,7 @@ import SortBy from '../helpers/SortBy.vue';
5353
import { computed, type InputHTMLAttributes, type Component, ref, type Ref, getCurrentInstance } from 'vue';
5454
import { useChildrenTracker } from '../use';
5555
import { FormInputsKey } from './Form/common';
56+
import { getUniqueId } from '../util';
5657
5758
defineOptions({
5859
name: 'PfRadio',
@@ -101,6 +102,8 @@ const ouiaProps = useOUIAProps({id: props.ouiaId, safe: props.ouiaSafe});
101102
const wrapWithLabel = computed(() => props.component === 'label');
102103
const input: Ref<HTMLInputElement | undefined> = ref();
103104
105+
const validId = computed(() => props.id || getUniqueId());
106+
104107
defineExpose({
105108
input,
106109
});

0 commit comments

Comments
 (0)