Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 16x 16x 16x 537x 537x | import { Ref, ComputedRef, ref, inject, computed } from 'vue'; import { DisabledKey } from '../constants'; /** * Provides a computed ref describing whether the component is disabled. * * This is based on two sources: * 1. The `disabled` prop or attribute of the component itself * 2. A provided `disabled` value, if there is one * * If either of these is true, the component should be disabled. * * @param disabledProp The disabled prop or attribute ref * @return A computed ref with a boolean value */ export default function useComputedDisabled( disabledProp: Ref<boolean> ) : ComputedRef<boolean> { // See if there is a provided value. If not, just set this to false. const providedDisabled = inject( DisabledKey, ref( false ) ); // Return true if either the provided value or the prop/attribute value is true. return computed( () => providedDisabled.value || disabledProp.value ); } |