Skip to content

Commit cb11564

Browse files
authored
Merge pull request #532 from Krishnaku007/improve-carousel-validation
Improve prop validation with descriptive warnings in Carousel component
2 parents ab59053 + 1d0c74f commit cb11564

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/components/Carousel/carouselProps.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export const carouselProps = {
3636
breakpointMode: {
3737
default: DEFAULT_CONFIG.breakpointMode,
3838
validator(value: BreakpointMode) {
39-
return BREAKPOINT_MODE_OPTIONS.includes(value)
39+
const isValid = BREAKPOINT_MODE_OPTIONS.includes(value)
40+
if (!isValid) {
41+
console.warn(`[vue3-carousel]: Invalid breakpointMode "${value}". Allowed values: ${BREAKPOINT_MODE_OPTIONS.join(', ')}`)
42+
}
43+
return isValid
4044
},
4145
},
4246
clamp: {
@@ -47,20 +51,13 @@ export const carouselProps = {
4751
type: String as PropType<Dir>,
4852
default: DEFAULT_CONFIG.dir,
4953
validator(value: Dir, props: { height?: string }) {
50-
// The value must match one of these strings
5154
if (!DIR_OPTIONS.includes(value)) {
55+
console.warn(`[vue3-carousel]: Invalid dir "${value}". Allowed values: ${DIR_OPTIONS.join(', ')}`)
5256
return false
5357
}
54-
55-
const normalizedDir =
56-
value in DIR_MAP ? DIR_MAP[value as NonNormalizedDir] : (value as NormalizedDir)
57-
if (
58-
['ttb', 'btt'].includes(normalizedDir) &&
59-
(!props.height || props.height === 'auto')
60-
) {
61-
console.warn(
62-
`[vue3-carousel]: The dir "${value}" is not supported with height "auto".`
63-
)
58+
const normalizedDir = value in DIR_MAP ? DIR_MAP[value as NonNormalizedDir] : (value as NormalizedDir)
59+
if (["ttb", "btt"].includes(normalizedDir) && (!props.height || props.height === "auto")) {
60+
console.warn(`[vue3-carousel]: The dir "${value}" is not supported with height "auto".`)
6461
}
6562
return true
6663
},
@@ -139,14 +136,22 @@ export const carouselProps = {
139136
type: String as PropType<SlideEffect>,
140137
default: DEFAULT_CONFIG.slideEffect,
141138
validator(value: SlideEffect) {
142-
return SLIDE_EFFECTS.includes(value)
139+
const isValid = SLIDE_EFFECTS.includes(value)
140+
if (!isValid) {
141+
console.warn(`[vue3-carousel]: Invalid slideEffect "${value}". Allowed values: ${SLIDE_EFFECTS.join(', ')}`)
142+
}
143+
return isValid
143144
},
144145
},
145146
// control snap position alignment
146147
snapAlign: {
147148
default: DEFAULT_CONFIG.snapAlign,
148149
validator(value: SnapAlign) {
149-
return SNAP_ALIGN_OPTIONS.includes(value)
150+
const isValid = SNAP_ALIGN_OPTIONS.includes(value)
151+
if (!isValid) {
152+
console.warn(`[vue3-carousel]: Invalid snapAlign "${value}". Allowed values: ${SNAP_ALIGN_OPTIONS.join(', ')}`)
153+
}
154+
return isValid
150155
},
151156
},
152157
// toggle touch dragging

0 commit comments

Comments
 (0)