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

feat(components): [container] add validation for the direction prop #16734

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/components/container/src/container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script lang="ts" setup>
import { computed, useSlots } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { isDirectionType } from '@element-plus/utils'

import type { Component, VNode } from 'vue'

Expand All @@ -18,6 +19,7 @@ const props = defineProps({
*/
direction: {
type: String,
validator: isDirectionType,
},
})
const slots = useSlots()
Expand Down
3 changes: 3 additions & 0 deletions packages/constants/container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const directionTypes = ['horizontal', 'vertical'] as const

export type DirectionType = typeof directionTypes[number]
1 change: 1 addition & 0 deletions packages/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './aria'
export * from './container'
export * from './date'
export * from './event'
export * from './key'
Expand Down
15 changes: 13 additions & 2 deletions packages/utils/vue/validator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { componentSizes, datePickTypes } from '@element-plus/constants'
import type { ComponentSize, DatePickType } from '@element-plus/constants'
import {
componentSizes,
datePickTypes,
directionTypes,
} from '@element-plus/constants'
import type {
ComponentSize,
DatePickType,
DirectionType,
} from '@element-plus/constants'

export const isValidComponentSize = (val: string): val is ComponentSize | '' =>
['', ...componentSizes].includes(val)

export const isValidDatePickType = (val: string): val is DatePickType =>
([...datePickTypes] as string[]).includes(val)

export const isDirectionType = (val: string): val is DirectionType =>
([...directionTypes] as string[]).includes(val)