Skip to content

Commit 4ddb835

Browse files
committed
refactor: enhance carousel properties validation and update styles for active slides
1 parent b18cfae commit 4ddb835

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

playground/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ select {
498498
}
499499
500500
.carousel__slide--active .carousel-item {
501-
border: 2px solid red;
501+
box-shadow: inset 0 0 0 2px red;
502502
}
503503
.config-panel-buttons-row {
504504
display: flex;

src/components/Carousel/Carousel.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ export const Carousel = defineComponent({
108108

109109
const dimension = computed(() => (isVertical.value ? 'height' : 'width'))
110110

111-
watchEffect(() => {
112-
if (isVertical.value && config.height === 'auto') {
113-
console.warn(
114-
'[Vue3-Carousel] To use vertical carousel mode, please provide a fixed height in the config.'
115-
)
116-
}
117-
})
118-
119111
function updateBreakpointsConfig(): void {
120112
if (!mounted.value) {
121113
return

src/components/Carousel/carouselProps.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PropType } from 'vue'
33
import {
44
BREAKPOINT_MODE_OPTIONS,
55
DEFAULT_CONFIG,
6+
DIR_MAP,
67
DIR_OPTIONS,
78
SLIDE_EFFECTS,
89
SNAP_ALIGN_OPTIONS,
@@ -14,6 +15,8 @@ import type {
1415
SnapAlign,
1516
CarouselConfig,
1617
SlideEffect,
18+
NonNormalizedDir,
19+
NormalizedDir,
1720
} from '@/shared'
1821

1922
export const carouselProps = {
@@ -100,9 +103,23 @@ export const carouselProps = {
100103
dir: {
101104
type: String as PropType<Dir>,
102105
default: DEFAULT_CONFIG.dir,
103-
validator(value: Dir) {
106+
validator(value: Dir, props: { height?: string }) {
104107
// The value must match one of these strings
105-
return DIR_OPTIONS.includes(value)
108+
if (!DIR_OPTIONS.includes(value)) {
109+
return false
110+
}
111+
112+
const normalizedDir =
113+
value in DIR_MAP ? DIR_MAP[value as NonNormalizedDir] : (value as NormalizedDir)
114+
if (
115+
['ttb', 'btt'].includes(normalizedDir) &&
116+
(!props.height || props.height === 'auto')
117+
) {
118+
console.warn(
119+
`[vue3-carousel warn]: The dir "${value}" is not supported with height "auto".`
120+
)
121+
}
122+
return true
106123
},
107124
},
108125
// aria-labels and additional text labels
@@ -125,13 +142,13 @@ export const carouselProps = {
125142
default: false,
126143
type: Boolean,
127144
validator(value: boolean, props: { wrapAround?: boolean }) {
128-
if (value && props.wrapAround)
129-
console.warn( /* eslint-disable-line no-console */
130-
'[vue3-carousel warn]: preventExcessiveDragging cannot be used with wrapAround. ' +
131-
'The preventExcessiveDragging setting will be ignored.'
132-
);
145+
if (value && props.wrapAround) {
146+
console.warn(
147+
`[vue3-carousel warn]: "preventExcessiveDragging" cannot be used with wrapAround. The setting will be ignored.`
148+
)
149+
}
133150

134-
return true;
135-
}
136-
}
151+
return true
152+
},
153+
},
137154
}

src/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ export const DEFAULT_CONFIG: CarouselConfig = {
6161
i18n: I18N_DEFAULT_CONFIG,
6262
ignoreAnimations: false,
6363
slideEffect: SLIDE_EFFECTS[0],
64-
preventExcessiveDragging: false
64+
preventExcessiveDragging: false,
6565
}

0 commit comments

Comments
 (0)