Skip to content

Commit

Permalink
fix(epicmaxco#2894): focus element in select and counter
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed Feb 18, 2023
1 parent e333e84 commit 9d216d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/ui/src/components/va-select/VaSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ import { useAutocomplete, useAutocompleteProps } from './hooks/useAutocomplete'
import type { SelectOption, Placement } from './types'
import type { DropdownOffsetProp } from '../va-dropdown/types'
import { blurElement, focusElement } from '../../utils/focus'
import { unwrapEl } from '../../utils/unwrapEl'
const VaDropdownProps = extractComponentProps(VaDropdown,
['keyboardNavigation', 'offset', 'stateful', 'keepAnchorWidth', 'closeOnContentClick', 'innerAnchorSelector', 'modelValue'],
Expand Down Expand Up @@ -614,15 +616,18 @@ export default defineComponent({
// public methods
const focus = () => {
if (props.disabled) { return }
input.value?.focus()
focusElement(unwrapEl(input.value))
}
const blur = () => {
if (showDropdownContentComputed.value) {
showDropdownContentComputed.value = false
}
nextTick(input.value?.blur)
nextTick(() => {
if (props.disabled) { return }
blurElement(unwrapEl(input.value))
})
}
const reset = () => withoutValidation(() => {
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/src/composables/useFocus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { unwrapEl } from './../utils/unwrapEl'
import { focusElement, blurElement } from './../utils/focus'
import { ref, onMounted, onBeforeUnmount, Ref } from 'vue'

export const useFocusEmits = ['focus', 'blur']
Expand All @@ -19,11 +21,13 @@ export function useFocus (
}

const focus = (): void => {
el?.value?.focus()
if (!el?.value) { return }
focusElement(unwrapEl(el?.value))
}

const blur = (): void => {
el?.value?.blur()
if (!el?.value) { return }
blurElement(unwrapEl(el?.value))
}

let element: any
Expand Down

0 comments on commit 9d216d9

Please sign in to comment.