mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-21 04:50:14 +08:00
feat: adds support for the enter key on the numeric keypad (#341)
This commit is contained in:
parent
362d2c29e7
commit
4e555a003c
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -151,6 +151,7 @@ export default defineComponent({
|
||||
switch (e.code) {
|
||||
case 'Space':
|
||||
case 'Enter':
|
||||
case 'NumpadEnter':
|
||||
toggle()
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ export default defineComponent({
|
||||
function handleInputKeyUp (e: KeyboardEvent): void {
|
||||
switch (e.code) {
|
||||
case 'Enter':
|
||||
case 'NumpadEnter':
|
||||
handleInputConfirm()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -522,6 +522,7 @@ export default defineComponent({
|
||||
handleWrapperKeyDownEsc()
|
||||
break
|
||||
case 'Enter':
|
||||
case 'NumpadEnter':
|
||||
handleWrapperKeyDownEnter(e)
|
||||
break
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) &&
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user