Skip to content

Commit 6346d75

Browse files
Ronan-FernandesRonan_Fernandes
authored and
Ronan_Fernandes
committed
Default social input send behavior
1 parent a0d1a3b commit 6346d75

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Meta } from '@storybook/addon-docs'
3030
- **submit** (function): Form submission handler.
3131
- **onCancelReply** (function, optional): Handler for canceling a reply.
3232
- **form** (UseFormReturn): react-hook-form form instance.
33+
- **onKeyDown** (function, optional): Custom keydown handler for the input field. Defaults to send with CTRL + Enter
3334

3435
## Notes
3536

@@ -63,6 +64,12 @@ const MyComponent = () => {
6364
submit={() => {}}
6465
onCancelReply={() => {}}
6566
form={useForm()}
67+
onKeyDown={(event) => {
68+
if (event.key === 'Enter' && !event.shiftKey) {
69+
event.preventDefault()
70+
console.log('Enter key pressed')
71+
}
72+
}}
6673
/>
6774
)
6875
}

packages/components/modules/__shared__/web/SocialInput/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const SocialInput = forwardRef<HTMLInputElement, SocialInputProps>(
6868
SocialUpsertActions = DefaultSocialUpsertActions,
6969
SubmitActions = DefaultSubmitActions,
7070
SubmitActionsProps = {},
71+
onKeyDown,
7172
formId = 'text-field-form',
7273
submit,
7374
isLoading,
@@ -78,8 +79,8 @@ const SocialInput = forwardRef<HTMLInputElement, SocialInputProps>(
7879
},
7980
ref,
8081
) => {
81-
const handleKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
82-
if (event.key === 'Enter' && !event.shiftKey) {
82+
const defaultKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
83+
if (event.key === 'Enter' && event.ctrlKey) {
8384
event.preventDefault()
8485
form.handleSubmit(submit)(event)
8586
}
@@ -93,7 +94,7 @@ const SocialInput = forwardRef<HTMLInputElement, SocialInputProps>(
9394
inputRef={ref}
9495
name={SOCIAL_UPSERT_FORM.body}
9596
control={form.control}
96-
onKeyDown={handleKeyDown}
97+
onKeyDown={onKeyDown ?? defaultKeyDown}
9798
placeholder={placeholder}
9899
autoFocus={autoFocusInput}
99100
isReply={isReply}

packages/components/modules/__shared__/web/SocialInput/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react'
1+
import { FC, KeyboardEvent } from 'react'
22

33
import { SocialTextFieldProps } from '@baseapp-frontend/design-system/components/web/inputs'
44

@@ -15,6 +15,7 @@ export interface SocialInputProps {
1515
SocialUpsertActions?: FC
1616
SubmitActions?: FC<SubmitActionsProps>
1717
SubmitActionsProps?: Partial<SubmitActionsProps>
18+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void
1819
formId?: string
1920
submit: (data: SocialUpsertForm) => void
2021
isLoading: boolean

0 commit comments

Comments
 (0)