Skip to content

Commit 3534780

Browse files
committed
fix(#613): separate computed breaks reactivity
The separated functions are a temporary solution. I may be able to incorporate generics to merge the functionality, but separate the differences
1 parent e86b6e0 commit 3534780

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

packages/bootstrap-vue-3/src/components/BForm/BFormInvalidFeedback.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// import type {BFormInvalidFeedbackProps} from '../../types/components'
99
import {computed, toRef} from 'vue'
1010
import type {Booleanish} from '../../types'
11-
import {useBooleanish} from '../../composables'
11+
import {useBooleanish, useBooleanishUndefined} from '../../composables'
1212
1313
interface BFormInvalidFeedbackProps {
1414
ariaLive?: string
@@ -28,8 +28,7 @@ const props = withDefaults(defineProps<BFormInvalidFeedbackProps>(), {
2828
})
2929
3030
const forceShowBoolean = useBooleanish(toRef(props, 'forceShow'))
31-
const stateBoolean =
32-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
31+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
3332
const tooltipBoolean = useBooleanish(toRef(props, 'tooltip'))
3433
3534
const computedShow = computed<boolean>(

packages/bootstrap-vue-3/src/components/BForm/BFormValidFeedback.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// import type {BFormValidFeedbackProps} from '../../types/components'
99
import {computed, toRef} from 'vue'
1010
import type {Booleanish} from '../../types'
11-
import {useBooleanish} from '../../composables'
11+
import {useBooleanish, useBooleanishUndefined} from '../../composables'
1212
1313
interface BFormValidFeedbackProps {
1414
ariaLive?: string
@@ -28,8 +28,7 @@ const props = withDefaults(defineProps<BFormValidFeedbackProps>(), {
2828
})
2929
3030
const forceShowBoolean = useBooleanish(toRef(props, 'forceShow'))
31-
const stateBoolean =
32-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
31+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
3332
const tooltipBoolean = useBooleanish(toRef(props, 'tooltip'))
3433
3534
const computedShow = computed<boolean>(

packages/bootstrap-vue-3/src/components/BFormCheckbox/BFormCheckbox.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@
3232
<script setup lang="ts">
3333
// import type {BFormCheckboxEmits, BFormCheckboxProps} from '../../types/components'
3434
import {computed, onMounted, reactive, Ref, ref, toRef} from 'vue'
35-
import {getClasses, getInputClasses, getLabelClasses, useBooleanish, useId} from '../../composables'
35+
import {
36+
getClasses,
37+
getInputClasses,
38+
getLabelClasses,
39+
useBooleanish,
40+
useBooleanishUndefined,
41+
useId,
42+
} from '../../composables'
3643
import type {Booleanish, ButtonVariant, InputSize} from '../../types'
3744
3845
interface BFormCheckboxProps {
@@ -80,20 +87,15 @@ const props = withDefaults(defineProps<BFormCheckboxProps>(), {
8087
value: true,
8188
})
8289
83-
const indeterminateBoolean =
84-
props.indeterminate !== undefined
85-
? useBooleanish(toRef(props, 'indeterminate') as Ref<Booleanish>)
86-
: computed(() => undefined)
90+
const indeterminateBoolean = useBooleanishUndefined(toRef(props, 'indeterminate'))
8791
const autofocusBoolean = useBooleanish(toRef(props, 'autofocus'))
8892
const plainBoolean = useBooleanish(toRef(props, 'plain'))
8993
const buttonBoolean = useBooleanish(toRef(props, 'button'))
9094
const switchBoolean = useBooleanish(toRef(props, 'switch'))
9195
const disabledBoolean = useBooleanish(toRef(props, 'disabled'))
9296
const inlineBoolean = useBooleanish(toRef(props, 'inline'))
93-
const requiredBoolean =
94-
props.required !== undefined ? useBooleanish(toRef(props, 'required')) : computed(() => undefined)
95-
const stateBoolean =
96-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
97+
const requiredBoolean = useBooleanishUndefined(toRef(props, 'required'))
98+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
9799
98100
interface BFormCheckboxEmits {
99101
(e: 'update:modelValue', value: unknown): void

packages/bootstrap-vue-3/src/components/BFormCheckbox/BFormCheckboxGroup.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
optionToElement,
3333
slotsToElements,
3434
useBooleanish,
35+
useBooleanishUndefined,
3536
useId,
3637
} from '../../composables'
3738
@@ -89,8 +90,7 @@ const disabledBoolean = useBooleanish(toRef(props, 'disabled'))
8990
const plainBoolean = useBooleanish(toRef(props, 'plain'))
9091
const requiredBoolean = useBooleanish(toRef(props, 'required'))
9192
const stackedBoolean = useBooleanish(toRef(props, 'stacked'))
92-
const stateBoolean =
93-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
93+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
9494
const switchesBoolean = useBooleanish(toRef(props, 'switches'))
9595
const validatedBoolean = useBooleanish(toRef(props, 'validated'))
9696

packages/bootstrap-vue-3/src/components/BFormRadio/BFormRadio.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@
3131
<script setup lang="ts">
3232
// import type {BFormRadioEmits, BFormRadioProps} from '../../types/components'
3333
import type {Booleanish, ButtonVariant, InputSize} from '../../types'
34-
import {getClasses, getInputClasses, getLabelClasses, useBooleanish, useId} from '../../composables'
34+
import {
35+
getClasses,
36+
getInputClasses,
37+
getLabelClasses,
38+
useBooleanish,
39+
useBooleanishUndefined,
40+
useId,
41+
} from '../../composables'
3542
import {computed, onMounted, reactive, ref, toRef} from 'vue'
3643
3744
interface BFormRadioProps {
@@ -83,8 +90,7 @@ const inlineBoolean = useBooleanish(toRef(props, 'inline'))
8390
const requiredBoolean = useBooleanish(toRef(props, 'required'))
8491
// TODO state is unused
8592
// eslint-disable-next-line @typescript-eslint/no-unused-vars
86-
const stateBoolean =
87-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
93+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
8894
8995
interface BFormRadioEmits {
9096
(e: 'input', value: boolean | string | Array<unknown> | Record<string, unknown> | number): void

packages/bootstrap-vue-3/src/components/BFormRadio/BFormRadioGroup.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
optionToElement,
3030
slotsToElements,
3131
useBooleanish,
32+
useBooleanishUndefined,
3233
useId,
3334
} from '../../composables'
3435
@@ -92,8 +93,7 @@ const requiredBoolean = useBooleanish(toRef(props, 'required'))
9293
const stackedBoolean = useBooleanish(toRef(props, 'stacked'))
9394
// TODO state is unused
9495
// eslint-disable-next-line @typescript-eslint/no-unused-vars
95-
const stateBoolean =
96-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
96+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
9797
// TODO validated is unused
9898
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9999
const validatedBoolean = useBooleanish(toRef(props, 'validated'))

packages/bootstrap-vue-3/src/components/BFormSelect/BFormSelect.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type {AriaInvalid, Booleanish, Size} from '../../types'
4444
import {computed, nextTick, onActivated, onMounted, ref, toRef} from 'vue'
4545
import BFormSelectOption from './BFormSelectOption.vue'
4646
import BFormSelectOptionGroup from './BFormSelectOptionGroup.vue'
47-
import {normalizeOptions, useBooleanish, useId} from '../../composables'
47+
import {normalizeOptions, useBooleanish, useBooleanishUndefined, useId} from '../../composables'
4848
4949
interface BFormSelectProps {
5050
ariaInvalid?: AriaInvalid
@@ -93,8 +93,7 @@ const disabledBoolean = useBooleanish(toRef(props, 'disabled'))
9393
const multipleBoolean = useBooleanish(toRef(props, 'multiple'))
9494
const plainBoolean = useBooleanish(toRef(props, 'plain'))
9595
const requiredBoolean = useBooleanish(toRef(props, 'required'))
96-
const stateBoolean =
97-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
96+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
9897
9998
interface BFormSelectEmits {
10099
(e: 'input', value: unknown): void

packages/bootstrap-vue-3/src/components/BFormTags/BFormTags.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
// import type {BFormTagsEmits, BFormTagsProps} from '../types/components'
109109
import {computed, onActivated, onMounted, ref, toRef, VNodeNormalizedChildren, watch} from 'vue'
110110
import BFormTag from './BFormTag.vue'
111-
import {useBooleanish, useId} from '../../composables'
111+
import {useBooleanish, useBooleanishUndefined, useId} from '../../composables'
112112
import type {Booleanish, ButtonVariant, ColorVariant, InputSize, InputType} from '../../types'
113113
114114
interface BFormTagsProps {
@@ -177,8 +177,7 @@ const noOuterFocusBoolean = useBooleanish(toRef(props, 'noOuterFocus'))
177177
const noTagRemoveBoolean = useBooleanish(toRef(props, 'noTagRemove'))
178178
const removeOnDeleteBoolean = useBooleanish(toRef(props, 'removeOnDelete'))
179179
const requiredBoolean = useBooleanish(toRef(props, 'required'))
180-
const stateBoolean =
181-
props.state !== undefined ? useBooleanish(toRef(props, 'state')) : computed(() => undefined)
180+
const stateBoolean = useBooleanishUndefined(toRef(props, 'state'))
182181
const tagPillsBoolean = useBooleanish(toRef(props, 'tagPills'))
183182
184183
interface BFormTagsEmits {

packages/bootstrap-vue-3/src/composables/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import {
1313
} from './useFormCheck'
1414
import useFormInput, {COMMON_INPUT_PROPS} from './useFormInput'
1515
import {normalizeOptions} from './useFormSelect'
16-
import useBooleanish from './useBooleanish'
16+
import {useBooleanish, useBooleanishUndefined} from './useBooleanish'
1717
import useId from './useId'
1818

1919
export {
2020
useAlignment,
21+
useBooleanishUndefined,
2122
createBreadcrumb,
2223
useBreadcrumb,
2324
useEventListener,
@@ -44,6 +45,7 @@ export default {
4445
useEventListener,
4546
bindGroupProps,
4647
getClasses,
48+
useBooleanishUndefined,
4749
getGroupAttr,
4850
getGroupClasses,
4951
getInputClasses,

packages/bootstrap-vue-3/src/composables/useBooleanish.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ import type {Booleanish} from '../types'
22
import {computed, ComputedRef, Ref} from 'vue'
33
import {resolveBooleanish} from '../utils'
44

5-
export default (el: Ref<Booleanish>): ComputedRef<boolean> =>
5+
export const useBooleanish = (el: Ref<Booleanish>): ComputedRef<boolean> =>
66
computed(() => resolveBooleanish(el.value))
7+
8+
export const useBooleanishUndefined = (
9+
el: Ref<Booleanish | undefined>
10+
): ComputedRef<boolean | undefined> =>
11+
computed(() => (el.value !== undefined ? resolveBooleanish(el.value) : undefined))

0 commit comments

Comments
 (0)