Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added enter handler for textbox #372 #2355

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ide/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
],
"types": [],
"baseUrl": "./node_modules",
"paths": {
"@fluentui/react": ["node_modules/@fluentui/react"]
},
"jsx": "preserve",
"esModuleInterop": true,
"include": ["src", "node_modules/@types"],
Comment on lines +15 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

"typeRoots": [
"node_modules/@types"
]
Expand Down
2 changes: 2 additions & 0 deletions py/examples/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async def serve(q: Q):
ui.text(f'textbox_numeric={q.args.textbox_numeric}'),
ui.text(f'textbox_tel={q.args.textbox_tel}'),
ui.text(f'textbox_password={q.args.textbox_password}'),
ui.text(f'textbox_one_enter={q.args.textbox_on_enter}'),
ui.button(name='show_form', label='Back', primary=True),
]
else:
Expand All @@ -46,6 +47,7 @@ async def serve(q: Q):
ui.textbox(name='textbox_numeric', label='With numeric keyboard (iOS, Android)', type='number'),
ui.textbox(name='textbox_tel', label='With telephone keyboard (iOS, Android)', type='tel'),
ui.textbox(name='textbox_password', label='Password', password=True),
ui.textbox(name='textbox_on_enter', label='Press Enter after typing', on_enter=True),
ui.button(name='show_inputs', label='Submit', primary=True),
])
await q.page.save()
10 changes: 10 additions & 0 deletions ui/src/textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export interface Textbox {
spellcheck?: B
/** Keyboard to be shown on mobile devices. Defaults to 'text'. */
type?: 'text' | 'number' | 'tel'
/**T rue if the Enter button is being pressed */
onEnter?: B
Comment on lines +70 to +71
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do this by default, no need for an extra prop.

}

const DEBOUNCE_TIMEOUT = 500
Expand All @@ -83,6 +85,13 @@ export const
setValue(v)
m.value = v
},
onKeyDown = (event: React.KeyboardEvent) => {
if(m.onEnter && event.key == 'Enter'){
event.preventDefault()
wave.args[m.name] = value
wave.push()
}
},
textFieldProps: Fluent.ITextFieldProps & { 'data-test': S } = {
'data-test': m.name,
label: m.label,
Expand All @@ -92,6 +101,7 @@ export const
disabled: m.disabled,
readOnly: m.readonly,
onChange,
onKeyDown,
iconProps: m.icon ? { iconName: m.icon } : undefined,
placeholder: m.placeholder,
prefix: m.prefix,
Expand Down