feat: adds support for the enter key on the numeric keypad (#341)

This commit is contained in:
Danny Feliz 2021-06-30 23:14:51 -04:00 committed by GitHub
parent 362d2c29e7
commit 4e555a003c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 18 additions and 8 deletions

View File

@ -175,6 +175,7 @@ export default defineComponent({
function handleKeyDown (e: KeyboardEvent): void {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
if (!isComposingRef.value) {
const pendingOptionData = menuInstRef.value?.getPendingOption()
if (pendingOptionData) {

View File

@ -135,6 +135,7 @@ const Button = defineComponent({
const handleKeyUp = (e: KeyboardEvent): void => {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
if (!props.keyboard) {
e.preventDefault()
return
@ -150,6 +151,7 @@ const Button = defineComponent({
const handleKeyDown = (e: KeyboardEvent): void => {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
if (!props.keyboard) return
e.preventDefault()
enterPressedRef.value = true

View File

@ -108,6 +108,7 @@ export default defineComponent({
function handleKeydown (e: KeyboardEvent, current: number): void {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
case 'Space':
setCurrent(current)
}

View File

@ -491,6 +491,7 @@ export default defineComponent({
if (props.filterable) return
// eslint-disable-next-line no-fallthrough
case 'Enter':
case 'NumpadEnter':
if (!mergedShowRef.value) {
openMenu()
} else {

View File

@ -151,6 +151,7 @@ export default defineComponent({
switch (e.code) {
case 'Space':
case 'Enter':
case 'NumpadEnter':
toggle()
}
}

View File

@ -115,6 +115,7 @@ export default defineComponent({
function handleInputKeyUp (e: KeyboardEvent): void {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
handleInputConfirm()
}
}

View File

@ -276,7 +276,7 @@ export default defineComponent({
const handleAddClick = doAdd
const handleMinusClick = doMinus
function handleKeyDown (e: KeyboardEvent): void {
if (e.code === 'Enter') {
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
if (e.target === inputInstRef.value?.wrapperElRef) {
// hit input wrapper
// which means not activated

View File

@ -522,6 +522,7 @@ export default defineComponent({
handleWrapperKeyDownEsc()
break
case 'Enter':
case 'NumpadEnter':
handleWrapperKeyDownEnter(e)
break
}

View File

@ -255,7 +255,8 @@ export default defineComponent({
} else if (
e.code === 'ArrowUp' ||
e.code === 'ArrowDown' ||
e.code === 'Enter'
e.code === 'Enter' ||
e.code === 'NumpadEnter'
) {
if (inputInstRef.value?.isCompositing) return
const { value: selectMenuInst } = selectMenuInstRef

View File

@ -228,7 +228,7 @@ export default defineComponent({
doUpdatePageSize(value)
}
function handleQuickJumperKeyUp (e: KeyboardEvent): void {
if (e.code === 'Enter') {
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
const page = parseInt(jumperValueRef.value)
if (
!Number.isNaN(page) &&

View File

@ -58,9 +58,8 @@ export interface RadioGroupInjection {
doUpdateValue: (value: string | number) => void
}
export const radioGroupInjectionKey: InjectionKey<RadioGroupInjection> = Symbol(
'radioGroup'
)
export const radioGroupInjectionKey: InjectionKey<RadioGroupInjection> =
Symbol('radioGroup')
export interface UseRadio {
mergedClsPrefix: Ref<string>
@ -153,6 +152,7 @@ function setup (props: ExtractPropTypes<typeof radioProps>): UseRadio {
function handleKeyUp (e: KeyboardEvent): void {
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
inputRef.value?.click()
}
}

View File

@ -550,6 +550,7 @@ export default defineComponent({
if (props.filterable) break
// eslint-disable-next-line no-fallthrough
case 'Enter':
case 'NumpadEnter':
if (mergedShowRef.value) {
const menu = menuRef.value
const pendingOptionData = menu?.getPendingOption()

View File

@ -437,7 +437,7 @@ export default defineComponent({
}
}
function handleKeyup (e: KeyboardEvent): void {
if (e.code === 'Enter') {
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
if (mergedShowRef.value) {
treeHandleKeyup(e)
if (!props.multiple) {

View File

@ -53,7 +53,7 @@ export function useKeyboard ({
const { value: fNodes } = fNodesRef
let fIndex = fNodes.findIndex((tmNode) => tmNode.key === pendingNodeKey)
if (!~fIndex) return
if (e.code === 'Enter') {
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
handleSelect(fNodes[fIndex])
} else if (e.code === 'ArrowDown') {
fIndex += 1