fix(components): [select] iOS keyboard not appear when focus (#11498)

* fix(components): [select] ios keyboard not appear when focus
This commit is contained in:
井柏然 2023-03-13 22:52:10 +08:00 committed by GitHub
parent a9ef3f0502
commit c89cc2d3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -173,6 +173,18 @@
@input="debouncedQueryChange" @input="debouncedQueryChange"
/> />
</div> </div>
<!-- fix: https://github.com/element-plus/element-plus/issues/11415 -->
<input
v-if="isIOS && !multiple && filterable && readonly"
ref="iOSInput"
:class="[
nsSelect.e('input'),
nsSelect.is(selectSize),
nsSelect.em('input', 'iOS'),
]"
:disabled="selectDisabled"
type="text"
/>
<el-input <el-input
:id="id" :id="id"
ref="reference" ref="reference"
@ -283,7 +295,7 @@ import {
toRefs, toRefs,
unref, unref,
} from 'vue' } from 'vue'
import { useResizeObserver } from '@vueuse/core' import { isIOS, useResizeObserver } from '@vueuse/core'
import { placements } from '@popperjs/core' import { placements } from '@popperjs/core'
import { ClickOutside } from '@element-plus/directives' import { ClickOutside } from '@element-plus/directives'
import { useFocus, useLocale, useNamespace } from '@element-plus/hooks' import { useFocus, useLocale, useNamespace } from '@element-plus/hooks'
@ -482,6 +494,7 @@ export default defineComponent({
reference, reference,
input, input,
iOSInput,
tooltipRef, tooltipRef,
tags, tags,
selectWrapper, selectWrapper,
@ -610,6 +623,7 @@ export default defineComponent({
} }
return { return {
isIOS,
onOptionsRendered, onOptionsRendered,
tagInMultiLine, tagInMultiLine,
prefixWidth, prefixWidth,
@ -666,6 +680,7 @@ export default defineComponent({
reference, reference,
input, input,
iOSInput,
tooltipRef, tooltipRef,
popperPaneRef, popperPaneRef,
tags, tags,

View File

@ -87,6 +87,7 @@ export const useSelect = (props, states: States, ctx) => {
input: HTMLInputElement input: HTMLInputElement
}> | null>(null) }> | null>(null)
const input = ref<HTMLInputElement | null>(null) const input = ref<HTMLInputElement | null>(null)
const iOSInput = ref<HTMLInputElement | null>(null)
const tooltipRef = ref<InstanceType<typeof ElTooltip> | null>(null) const tooltipRef = ref<InstanceType<typeof ElTooltip> | null>(null)
const tags = ref<HTMLElement | null>(null) const tags = ref<HTMLElement | null>(null)
const selectWrapper = ref<HTMLElement | null>(null) const selectWrapper = ref<HTMLElement | null>(null)
@ -303,6 +304,7 @@ export const useSelect = (props, states: States, ctx) => {
if (props.filterable) { if (props.filterable) {
states.filteredOptionsCount = states.optionsCount states.filteredOptionsCount = states.optionsCount
states.query = props.remote ? '' : states.selectedLabel states.query = props.remote ? '' : states.selectedLabel
iOSInput.value?.focus?.()
if (props.multiple) { if (props.multiple) {
input.value?.focus() input.value?.focus()
} else { } else {
@ -790,6 +792,7 @@ export const useSelect = (props, states: States, ctx) => {
const blur = () => { const blur = () => {
states.visible = false states.visible = false
reference.value?.blur() reference.value?.blur()
iOSInput.value?.blur?.()
} }
const handleBlur = (event: FocusEvent) => { const handleBlur = (event: FocusEvent) => {
@ -954,6 +957,7 @@ export const useSelect = (props, states: States, ctx) => {
// DOM ref // DOM ref
reference, reference,
input, input,
iOSInput,
tooltipRef, tooltipRef,
tags, tags,
selectWrapper, selectWrapper,

View File

@ -175,6 +175,13 @@
height: 28px; height: 28px;
background-color: transparent; background-color: transparent;
&--iOS {
position: absolute;
left: 0;
top: 0;
z-index: 6;
}
@include when(small) { @include when(small) {
height: 14px; height: 14px;
} }