Skip to content

Commit

Permalink
Merge pull request #12281 from element-plus/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
iamkun committed Mar 31, 2023
2 parents 54c4e15 + 80a0057 commit 44d39ac
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 51 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
## Changelog

### 2.3.2

_2023-03-31_

#### Features

- Components [form] scroll-into-view options (#12164 by @ryuhangyeong)

#### Bug fixes

- Components [select-v2] reset hoverindex when close dropdown list (#12090 by @btea)
- Components [input] scrollbar not hide after autosize (#10137 by @HeftyKoo)
- Docs [tabs] example type error (#12160 by @bigsnowballhehe)
- Components [input] textarea height calc (#12087 by @MrWeilian)
- Components [select] multiple disabled style (#12015 by @MrWeilian)
- Components [pagination] delete input value display empty string (#12134 by @btea)
- Upload data is not independent (#12029 by @jianjunyuu)
- Style(components): [Tabs] Modify tabs to flex layout (#12048 by @kooriookami)

### 2.3.1

_2023-03-19_
Expand Down
10 changes: 1 addition & 9 deletions docs/.vitepress/config/sponsors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,7 @@ export const leftCustomImgSponsors = [
slogan: 'JNPF low code development platform to develop simple!',
slogan_cn: 'JNPF 低代码开发平台,让开发变得简单!',
className: 'jnpf',
banner_img: '/images/jnpfsoft.jpg',
},
{
name: 'JeePlus',
img: '/images/sponsors/jeeplus.png',
url: 'http://www.jeeplus.org/#/demo?from=ele',
slogan: 'JeePlus development platform',
slogan_cn: 'JeePlus 快速开发平台',
banner_img: '/images/sponsors/jeeplus_banner.jpg',
banner_img: '/images/sponsors/jnpfsoft.jpg',
},
]

Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/vitepress/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ details {
margin: 16px 0;
font-size: 18px;
font-weight: 600;
cursor: pointer;
}
}

Expand Down
35 changes: 18 additions & 17 deletions docs/en-US/component/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,24 @@ form/accessibility

### Form Attributes

| Name | Description | Type | Default |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------- | ------- |
| model | Data of form component. | ^[object]`Record<string, any>` ||
| rules | Validation rules of form. | ^[object]`FormRules` ||
| inline | Whether the form is inline. | ^[boolean] | false |
| label-position | Position of label. If set to `'left'` or `'right'`, `label-width` prop is also required. | ^[enum]`'left' \| 'right' \| 'top'` | right |
| label-width | Width of label, e.g. `'50px'`. All its direct child form items will inherit this value. `auto` is supported. | ^[string] / ^[number] ||
| label-suffix | Suffix of the label. | ^[string] ||
| hide-required-asterisk | Whether to hide required fields should have a red asterisk (star) beside their labels. | ^[boolean] | false |
| require-asterisk-position | Position of asterisk. | ^[enum]`'left' \| 'right'` | left |
| show-message | Whether to show the error message. | ^[boolean] | true |
| inline-message | Whether to display the error message inline with the form item. | ^[boolean] | false |
| status-icon | Whether to display an icon indicating the validation result. | ^[boolean] | false |
| validate-on-rule-change | Whether to trigger validation when the `rules` prop is changed. | ^[boolean] | true |
| size | Control the size of components in this form. | ^[enum]`'large' \| 'default' \| 'small'` ||
| disabled | Whether to disable all components in this form. If set to `true`, it will override the `disabled` prop of the inner component. | ^[boolean] | false |
| scroll-to-error | When validation fails, scroll to the first error form entry. | ^[boolean] | false |
| Name | Description | Type | Default |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | ------- |
| model | Data of form component. | ^[object]`Record<string, any>` ||
| rules | Validation rules of form. | ^[object]`FormRules` ||
| inline | Whether the form is inline. | ^[boolean] | false |
| label-position | Position of label. If set to `'left'` or `'right'`, `label-width` prop is also required. | ^[enum]`'left' \| 'right' \| 'top'` | right |
| label-width | Width of label, e.g. `'50px'`. All its direct child form items will inherit this value. `auto` is supported. | ^[string] / ^[number] ||
| label-suffix | Suffix of the label. | ^[string] ||
| hide-required-asterisk | Whether to hide required fields should have a red asterisk (star) beside their labels. | ^[boolean] | false |
| require-asterisk-position | Position of asterisk. | ^[enum]`'left' \| 'right'` | left |
| show-message | Whether to show the error message. | ^[boolean] | true |
| inline-message | Whether to display the error message inline with the form item. | ^[boolean] | false |
| status-icon | Whether to display an icon indicating the validation result. | ^[boolean] | false |
| validate-on-rule-change | Whether to trigger validation when the `rules` prop is changed. | ^[boolean] | true |
| size | Control the size of components in this form. | ^[enum]`'large' \| 'default' \| 'small'` ||
| disabled | Whether to disable all components in this form. If set to `true`, it will override the `disabled` prop of the inner component. | ^[boolean] | false |
| scroll-to-error | When validation fails, scroll to the first error form entry. | ^[boolean] | false |
| scroll-into-view-options | When validation fails, it scrolls to the first error item based on the scrollIntoView option. [scrollIntoView](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView). | ^[object] / ^[boolean] ||

### Form Methods

Expand Down
6 changes: 5 additions & 1 deletion docs/examples/tabs/dynamic-tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import type { TabPaneName } from 'element-plus'
let tabIndex = 2
const editableTabsValue = ref('2')
Expand All @@ -34,7 +35,10 @@ const editableTabs = ref([
},
])
const handleTabsEdit = (targetName: string, action: 'remove' | 'add') => {
const handleTabsEdit = (
targetName: TabPaneName | undefined,
action: 'remove' | 'add'
) => {
if (action === 'add') {
const newTabName = `${++tabIndex}`
editableTabs.value.push({
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/upload/basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
const beforeRemove: UploadProps['beforeRemove'] = (uploadFile, uploadFiles) => {
return ElMessageBox.confirm(
`Cancel the transfert of ${uploadFile.name} ?`
`Cancel the transfer of ${uploadFile.name} ?`
).then(
() => true,
() => false
Expand Down
Binary file removed docs/public/images/jnpfsoft.jpg
Binary file not shown.
Binary file added docs/public/images/sponsors/jnpfsoft.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/components/form/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export const formProps = buildProps({
* @description When validation fails, scroll to the first error form entry.
*/
scrollToError: Boolean,
/**
* @description When validation fails, it scrolls to the first error item based on the scrollIntoView option.
*/
scrollIntoViewOptions: {
type: [Object, Boolean],
},
} as const)
export type FormProps = ExtractPropTypes<typeof formProps>
export type FormMetaProps = ExtractPropTypes<typeof formMetaProps>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/form/src/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const validateField: FormContext['validateField'] = async (
const scrollToField = (prop: FormItemProp) => {
const field = filterFields(fields, prop)[0]
if (field) {
field.$el?.scrollIntoView()
field.$el?.scrollIntoView(props.scrollIntoViewOptions)
}
}
Expand Down
30 changes: 29 additions & 1 deletion packages/components/input/src/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ const suffixVisible = computed(
const [recordCursor, setCursor] = useCursor(input)
useResizeObserver(textarea, (entries) => {
onceInitSizeTextarea()
if (!isWordLimitVisible.value || props.resize !== 'both') return
const entry = entries[0]
const { width } = entry.contentRect
Expand All @@ -330,16 +331,43 @@ const resizeTextarea = () => {
if (autosize) {
const minRows = isObject(autosize) ? autosize.minRows : undefined
const maxRows = isObject(autosize) ? autosize.maxRows : undefined
const textareaStyle = calcTextareaHeight(textarea.value, minRows, maxRows)
// If the scrollbar is displayed, the height of the textarea needs more space than the calculated height.
// If set textarea height in this case, the scrollbar will not hide.
// So we need to hide scrollbar first, and reset it in next tick.
// see https://github.com/element-plus/element-plus/issues/8825
textareaCalcStyle.value = {
...calcTextareaHeight(textarea.value, minRows, maxRows),
overflowY: 'hidden',
...textareaStyle,
}
nextTick(() => {
// NOTE: Force repaint to make sure the style set above is applied.
textarea.value!.offsetHeight
textareaCalcStyle.value = textareaStyle
})
} else {
textareaCalcStyle.value = {
minHeight: calcTextareaHeight(textarea.value).minHeight,
}
}
}
const createOnceInitResize = (resizeTextarea: () => void) => {
let isInit = false
return () => {
if (isInit || !props.autosize) return
const isElHidden = textarea.value?.offsetParent === null
if (!isElHidden) {
resizeTextarea()
isInit = true
}
}
}
// fix: https://github.com/element-plus/element-plus/issues/12074
const onceInitSizeTextarea = createOnceInitResize(resizeTextarea)
const setNativeInputValue = () => {
const input = _ref.value
if (!input || input.value === nativeInputValue.value) return
Expand Down
6 changes: 3 additions & 3 deletions packages/components/pagination/src/components/jumper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ defineProps(paginationJumperProps)
const { t } = useLocale()
const ns = useNamespace('pagination')
const { pageCount, disabled, currentPage, changeEvent } = usePagination()
const userInput = ref<number>()
const userInput = ref<number | string>()
const innerValue = computed(() => userInput.value ?? currentPage?.value)
function handleInput(val: number | string) {
userInput.value = +val
userInput.value = val ? +val : ''
}
function handleChange(val: number | string) {
val = Math.trunc(+val)
changeEvent?.(+val)
changeEvent?.(val)
userInput.value = undefined
}
</script>
9 changes: 9 additions & 0 deletions packages/components/select-v2/src/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,15 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
return nextTick(menuRef.value.resetScrollTop)
})

watch(
() => dropdownMenuVisible.value,
(val) => {
if (!val) {
resetHoveringIndex()
}
}
)

onMounted(() => {
initStates()
})
Expand Down
11 changes: 9 additions & 2 deletions packages/components/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
<div
v-if="multiple"
ref="tags"
:class="nsSelect.e('tags')"
:class="[
nsSelect.e('tags'),
nsSelect.is('disabled', selectDisabled),
]"
:style="selectTagsStyle"
>
<transition
Expand Down Expand Up @@ -145,7 +148,11 @@
ref="input"
v-model="query"
type="text"
:class="[nsSelect.e('input'), nsSelect.is(selectSize)]"
:class="[
nsSelect.e('input'),
nsSelect.is(selectSize),
nsSelect.is('disabled', selectDisabled),
]"
:disabled="selectDisabled"
:autocomplete="autocomplete"
:style="{
Expand Down
19 changes: 15 additions & 4 deletions packages/components/upload/src/upload-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { isObject } from '@vue/shared'
import { cloneDeep } from 'lodash-unified'
import { useNamespace } from '@element-plus/hooks'
import { entriesOf } from '@element-plus/utils'
import { useFormDisabled } from '@element-plus/components/form'
import UploadDragger from './upload-dragger.vue'
import { uploadContentProps } from './upload-content'
import { genFileId } from './upload'
import type { UploadContentProps } from './upload-content'
import type {
UploadFile,
Expand Down Expand Up @@ -86,8 +89,12 @@ const upload = async (rawFile: UploadRawFile) => {
}
let hookResult: Exclude<ReturnType<UploadHooks['beforeUpload']>, Promise<any>>
let beforeData: UploadContentProps['data'] = {}
try {
hookResult = await props.beforeUpload(rawFile)
const beforeUploadPromise = props.beforeUpload(rawFile)
beforeData = isObject(props.data) ? cloneDeep(props.data) : props.data
hookResult = await beforeUploadPromise
} catch {
hookResult = false
}
Expand All @@ -111,11 +118,15 @@ const upload = async (rawFile: UploadRawFile) => {
doUpload(
Object.assign(file, {
uid: rawFile.uid,
})
}),
beforeData
)
}
const doUpload = (rawFile: UploadRawFile) => {
const doUpload = (
rawFile: UploadRawFile,
beforeData?: UploadContentProps['data']
) => {
const {
headers,
data,
Expand All @@ -134,7 +145,7 @@ const doUpload = (rawFile: UploadRawFile) => {
headers: headers || {},
withCredentials,
file: rawFile,
data,
data: beforeData ?? data,
method,
filename,
action,
Expand Down
7 changes: 7 additions & 0 deletions packages/theme-chalk/src/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
height: 28px;
background-color: transparent;

@include when(disabled) {
cursor: not-allowed;
}

&--iOS {
position: absolute;
left: 0;
Expand Down Expand Up @@ -208,6 +212,9 @@
top: 50%;
transform: translateY(-50%);
@include select-tag-normal;
@include when(disabled) {
cursor: not-allowed;
}
}

@include e(collapse-tags) {
Expand Down

0 comments on commit 44d39ac

Please sign in to comment.