import { ref, inject, computed } from 'vue'; import '../../../constants/index.mjs'; import '../../form/index.mjs'; import '../../../hooks/index.mjs'; import '../../../utils/index.mjs'; import { radioGroupKey } from './constants.mjs'; import { isPropAbsent } from '../../../utils/types.mjs'; import { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs'; import { useFormSize, useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs'; import { useDeprecated } from '../../../hooks/use-deprecated/index.mjs'; const useRadio = (props, emit) => { const radioRef = ref(); const radioGroup = inject(radioGroupKey, void 0); const isGroup = computed(() => !!radioGroup); const actualValue = computed(() => { if (!isPropAbsent(props.value)) { return props.value; } return props.label; }); const modelValue = computed({ get() { return isGroup.value ? radioGroup.modelValue : props.modelValue; }, set(val) { if (isGroup.value) { radioGroup.changeEvent(val); } else { emit && emit(UPDATE_MODEL_EVENT, val); } radioRef.value.checked = props.modelValue === actualValue.value; } }); const size = useFormSize(computed(() => radioGroup == null ? void 0 : radioGroup.size)); const disabled = useFormDisabled(computed(() => radioGroup == null ? void 0 : radioGroup.disabled)); const focus = ref(false); const tabIndex = computed(() => { return disabled.value || isGroup.value && modelValue.value !== actualValue.value ? -1 : 0; }); useDeprecated({ from: "label act as value", replacement: "value", version: "3.0.0", scope: "el-radio", ref: "https://element-plus.org/en-US/component/radio.html" }, computed(() => isGroup.value && isPropAbsent(props.value))); return { radioRef, isGroup, radioGroup, focus, size, disabled, tabIndex, modelValue, actualValue }; }; export { useRadio }; //# sourceMappingURL=use-radio.mjs.map