option-group.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { defineComponent, ref, getCurrentInstance, provide, reactive, toRefs, inject, onMounted, toRaw, watch, withDirectives, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, renderSlot, vShow } from 'vue';
  2. import '../../../hooks/index.mjs';
  3. import { selectGroupKey, selectKey } from './token.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. const _sfc_main = defineComponent({
  7. name: "ElOptionGroup",
  8. componentName: "ElOptionGroup",
  9. props: {
  10. label: String,
  11. disabled: {
  12. type: Boolean,
  13. default: false
  14. }
  15. },
  16. setup(props) {
  17. const ns = useNamespace("select");
  18. const visible = ref(true);
  19. const instance = getCurrentInstance();
  20. const children = ref([]);
  21. provide(selectGroupKey, reactive({
  22. ...toRefs(props)
  23. }));
  24. const select = inject(selectKey);
  25. onMounted(() => {
  26. children.value = flattedChildren(instance.subTree);
  27. });
  28. const flattedChildren = (node) => {
  29. const children2 = [];
  30. if (Array.isArray(node.children)) {
  31. node.children.forEach((child) => {
  32. var _a;
  33. if (child.type && child.type.name === "ElOption" && child.component && child.component.proxy) {
  34. children2.push(child.component.proxy);
  35. } else if ((_a = child.children) == null ? void 0 : _a.length) {
  36. children2.push(...flattedChildren(child));
  37. }
  38. });
  39. }
  40. return children2;
  41. };
  42. const { groupQueryChange } = toRaw(select);
  43. watch(groupQueryChange, () => {
  44. visible.value = children.value.some((option) => option.visible === true);
  45. }, { flush: "post" });
  46. return {
  47. visible,
  48. ns
  49. };
  50. }
  51. });
  52. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  53. return withDirectives((openBlock(), createElementBlock("ul", {
  54. class: normalizeClass(_ctx.ns.be("group", "wrap"))
  55. }, [
  56. createElementVNode("li", {
  57. class: normalizeClass(_ctx.ns.be("group", "title"))
  58. }, toDisplayString(_ctx.label), 3),
  59. createElementVNode("li", null, [
  60. createElementVNode("ul", {
  61. class: normalizeClass(_ctx.ns.b("group"))
  62. }, [
  63. renderSlot(_ctx.$slots, "default")
  64. ], 2)
  65. ])
  66. ], 2)), [
  67. [vShow, _ctx.visible]
  68. ]);
  69. }
  70. var OptionGroup = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/element-plus/element-plus/packages/components/select/src/option-group.vue"]]);
  71. export { OptionGroup as default };
  72. //# sourceMappingURL=option-group.mjs.map