Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve issue with disabled property in options not working #6595

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions ui/src/formkit/inputs/select/SelectMain.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script lang="ts" setup>
import type { FormKitFrameworkContext } from "@formkit/core";
import { axiosInstance } from "@halo-dev/api-client";
import { useDebounceFn } from "@vueuse/core";
import { useFuse } from "@vueuse/integrations/useFuse";
import type { AxiosRequestConfig } from "axios";
import { get, has, type PropertyPath } from "lodash-es";
import {
computed,
onMounted,
Expand All @@ -9,12 +14,8 @@ import {
watch,
type PropType,
} from "vue";
import { isFalse } from "./isFalse";
import SelectContainer from "./SelectContainer.vue";
import { axiosInstance } from "@halo-dev/api-client";
import { get, has, type PropertyPath } from "lodash-es";
import { useDebounceFn } from "@vueuse/core";
import { useFuse } from "@vueuse/integrations/useFuse";
import type { AxiosRequestConfig } from "axios";

export interface SelectProps {
/**
Expand Down Expand Up @@ -230,10 +231,6 @@ const initSelectProps = () => {
}
};

const isFalse = (value: string | boolean | undefined | null) => {
return [undefined, null, "false", false].includes(value);
};

const isLoading = ref(false);
const isFetchingMore = ref(false);
const page = ref(1);
Expand Down
15 changes: 10 additions & 5 deletions ui/src/formkit/inputs/select/SelectOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { vScroll } from "@vueuse/components";
import { useEventListener, type UseScrollReturn } from "@vueuse/core";
import { computed, ref, watch } from "vue";
import SelectOptionItem from "./SelectOptionItem.vue";
import { isFalse } from "./isFalse";
const props = defineProps<{
options: Array<Record<string, unknown> & { label: string; value: string }>;
Expand Down Expand Up @@ -81,7 +82,7 @@ const handleSelected = (index: number) => {
}
}
selectedIndex.value = index;
if (option) {
if (option && !isDisabled(option)) {
emit("selected", option);
}
};
Expand Down Expand Up @@ -112,11 +113,15 @@ const reachMaximumLimit = computed(() => {
return false;
});
const isDisabled = (option: { label: string; value: string }) => {
const isDisabled = (
option: Record<string, unknown> & { label: string; value: string }
) => {
const attrs = option.attrs as Record<string, unknown>;
return (
reachMaximumLimit.value &&
selectedValues.value &&
!selectedValues.value.includes(option.value)
(reachMaximumLimit.value &&
selectedValues.value &&
!selectedValues.value.includes(option.value)) ||
!isFalse(attrs?.disabled as string | boolean | undefined)
);
};
Expand Down
3 changes: 3 additions & 0 deletions ui/src/formkit/inputs/select/isFalse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isFalse = (value: string | boolean | undefined | null) => {
return [undefined, null, "false", false].includes(value);
};
Loading