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: input-number unregistered input and checkgroup disabled fix #514

Merged
merged 2 commits into from
Mar 31, 2022
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
3 changes: 2 additions & 1 deletion src/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default defineComponent({
},

setup(props) {
const formDisabled = useFormDisabled();
const labelRef = ref<HTMLElement>();
if (props.needRipple) {
useRipple(labelRef);
Expand All @@ -28,6 +27,8 @@ export default defineComponent({
const [innerChecked, setInnerChecked] = useVModel(checked, modelValue, props.defaultChecked, props.onChange);

const checkboxGroup = inject(CheckboxGroupInjectionKey, undefined);
const { disabled: GroupDisabled } = toRefs(props);
const formDisabled = useFormDisabled(GroupDisabled);

const name = computed<string>(() => props.name || checkboxGroup?.name);

Expand Down
6 changes: 3 additions & 3 deletions src/form/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ref, inject, computed, getCurrentInstance } from 'vue';
import { Ref, inject, unref, computed, getCurrentInstance } from 'vue';
import { TdFormProps } from './type';

export interface FormDisabledProvider {
Expand All @@ -9,9 +9,9 @@ export interface FormDisabledProvider {
* 用于实现 form 的全局禁用状态hook
* @returns
*/
export function useFormDisabled() {
export function useFormDisabled(extend?: Ref<boolean>) {
const { props } = getCurrentInstance();
const propsDisabled = computed(() => props.disabled as boolean);
const { disabled } = inject<FormDisabledProvider>('formDisabled', Object.create(null));
return computed(() => propsDisabled.value || disabled?.value);
return computed(() => propsDisabled.value || disabled?.value || extend?.value);
}
2 changes: 2 additions & 0 deletions src/input-number/input-number.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineComponent, VNode } from 'vue';
import { AddIcon, RemoveIcon, ChevronDownIcon, ChevronUpIcon } from 'tdesign-icons-vue-next';
import TButton from '../button';
import TInput from '../input';
import CLASSNAMES from '../utils/classnames';
import props from './props';
import { ChangeSource, TdInputNumberProps } from './type';
Expand Down Expand Up @@ -44,6 +45,7 @@ export default defineComponent({
ChevronDownIcon,
ChevronUpIcon,
TButton,
TInput,
},
props: { ...props },
emits: ['update:value', 'change', 'blur', 'focus', 'keydown-enter', 'keydown', 'keyup', 'keypress'],
Expand Down