bfdde465e5f78190e32c333df3590d6e8216943ed7442660004885e17358d456fc2786bcedc8d863112b5a47f4ff1deb1f0fd767a045cccc80c106c7741ff3 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var radioGroup = require('./radio-group.js');
  5. var constants = require('./constants.js');
  6. var lodashUnified = require('lodash-unified');
  7. var radio = require('./radio.js');
  8. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  9. var index = require('../../../hooks/use-namespace/index.js');
  10. var index$1 = require('../../../hooks/use-id/index.js');
  11. var useFormItem = require('../../form/src/hooks/use-form-item.js');
  12. var error = require('../../../utils/error.js');
  13. var event = require('../../../constants/event.js');
  14. const __default__ = vue.defineComponent({
  15. name: "ElRadioGroup"
  16. });
  17. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  18. ...__default__,
  19. props: radioGroup.radioGroupProps,
  20. emits: radioGroup.radioGroupEmits,
  21. setup(__props, { emit }) {
  22. const props = __props;
  23. const ns = index.useNamespace("radio");
  24. const radioId = index$1.useId();
  25. const radioGroupRef = vue.ref();
  26. const { formItem } = useFormItem.useFormItem();
  27. const { inputId: groupId, isLabeledByFormItem } = useFormItem.useFormItemInputId(props, {
  28. formItemContext: formItem
  29. });
  30. const changeEvent = (value) => {
  31. emit(event.UPDATE_MODEL_EVENT, value);
  32. vue.nextTick(() => emit(event.CHANGE_EVENT, value));
  33. };
  34. vue.onMounted(() => {
  35. const radios = radioGroupRef.value.querySelectorAll("[type=radio]");
  36. const firstLabel = radios[0];
  37. if (!Array.from(radios).some((radio) => radio.checked) && firstLabel) {
  38. firstLabel.tabIndex = 0;
  39. }
  40. });
  41. const name = vue.computed(() => {
  42. return props.name || radioId.value;
  43. });
  44. const aliasProps = vue.computed(() => ({
  45. ...radioGroup.radioDefaultProps,
  46. ...props.props
  47. }));
  48. const getOptionProps = (option) => {
  49. const base = {
  50. label: option[aliasProps.value.label],
  51. value: option[aliasProps.value.value],
  52. disabled: option[aliasProps.value.disabled]
  53. };
  54. return { ...option, ...base };
  55. };
  56. vue.provide(constants.radioGroupKey, vue.reactive({
  57. ...vue.toRefs(props),
  58. changeEvent,
  59. name
  60. }));
  61. vue.watch(() => props.modelValue, (newVal, oldValue) => {
  62. if (props.validateEvent && !lodashUnified.isEqual(newVal, oldValue)) {
  63. formItem == null ? void 0 : formItem.validate("change").catch((err) => error.debugWarn());
  64. }
  65. });
  66. return (_ctx, _cache) => {
  67. return vue.openBlock(), vue.createElementBlock("div", {
  68. id: vue.unref(groupId),
  69. ref_key: "radioGroupRef",
  70. ref: radioGroupRef,
  71. class: vue.normalizeClass(vue.unref(ns).b("group")),
  72. role: "radiogroup",
  73. "aria-label": !vue.unref(isLabeledByFormItem) ? _ctx.ariaLabel || "radio-group" : void 0,
  74. "aria-labelledby": vue.unref(isLabeledByFormItem) ? vue.unref(formItem).labelId : void 0
  75. }, [
  76. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  77. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(props.options, (item, index) => {
  78. return vue.openBlock(), vue.createBlock(radio["default"], vue.mergeProps({ key: index }, getOptionProps(item)), null, 16);
  79. }), 128))
  80. ])
  81. ], 10, ["id", "aria-label", "aria-labelledby"]);
  82. };
  83. }
  84. });
  85. var RadioGroup = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "radio-group.vue"]]);
  86. exports["default"] = RadioGroup;
  87. //# sourceMappingURL=radio-group2.js.map