mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
Feature: submit external controller when press enter
This commit is contained in:
parent
44dd8c6926
commit
614a20b684
@ -1,4 +1,5 @@
|
|||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
import { KeyboardEvent, FocusEvent, ChangeEvent } from 'react'
|
||||||
|
|
||||||
import { noop } from '@lib/helper'
|
import { noop } from '@lib/helper'
|
||||||
import { BaseComponentProps } from '@models/BaseProps'
|
import { BaseComponentProps } from '@models/BaseProps'
|
||||||
@ -11,8 +12,9 @@ interface InputProps extends BaseComponentProps {
|
|||||||
autoFocus?: boolean
|
autoFocus?: boolean
|
||||||
type?: string
|
type?: string
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onChange?: (value: string, event?: React.ChangeEvent<HTMLInputElement>) => void
|
onChange?: (value: string, event?: ChangeEvent<HTMLInputElement>) => void
|
||||||
onBlur?: (event?: React.FocusEvent<HTMLInputElement>) => void
|
onEnter?: (event?: KeyboardEvent<HTMLInputElement>) => void
|
||||||
|
onBlur?: (event?: FocusEvent<HTMLInputElement>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Input (props: InputProps) {
|
export function Input (props: InputProps) {
|
||||||
@ -27,9 +29,16 @@ export function Input (props: InputProps) {
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
onChange = noop,
|
onChange = noop,
|
||||||
onBlur = noop,
|
onBlur = noop,
|
||||||
|
onEnter = noop,
|
||||||
} = props
|
} = props
|
||||||
const classname = classnames('input', `text-${align}`, { 'focus:shadow-none': inside }, className)
|
const classname = classnames('input', `text-${align}`, { 'focus:shadow-none': inside }, className)
|
||||||
|
|
||||||
|
function handleKeyDown (e: KeyboardEvent<HTMLInputElement>) {
|
||||||
|
if (e.code === 'Enter') {
|
||||||
|
onEnter(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@ -40,6 +49,7 @@ export function Input (props: InputProps) {
|
|||||||
type={type}
|
type={type}
|
||||||
onChange={event => onChange(event.target.value, event)}
|
onChange={event => onChange(event.target.value, event)}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ export default function ExternalController () {
|
|||||||
inside={true}
|
inside={true}
|
||||||
value={value.hostname}
|
value={value.hostname}
|
||||||
onChange={hostname => set('hostname', hostname)}
|
onChange={hostname => set('hostname', hostname)}
|
||||||
|
onEnter={handleOk}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
@ -59,6 +60,7 @@ export default function ExternalController () {
|
|||||||
inside={true}
|
inside={true}
|
||||||
value={value.port}
|
value={value.port}
|
||||||
onChange={port => set('port', port)}
|
onChange={port => set('port', port)}
|
||||||
|
onEnter={handleOk}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
@ -69,6 +71,7 @@ export default function ExternalController () {
|
|||||||
inside={true}
|
inside={true}
|
||||||
value={value.secret}
|
value={value.secret}
|
||||||
onChange={secret => set('secret', secret)}
|
onChange={secret => set('secret', secret)}
|
||||||
|
onEnter={handleOk}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user