Skip to content

Commit e671963

Browse files
Ronan-Fernandespt-tsl
authored andcommitted
BA-2197: default social input send behavior (#199)
* Default social input send behavior * Versioning
1 parent 7b22519 commit e671963

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

packages/components/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @baseapp-frontend/components
22

3+
## 1.0.7
4+
5+
### Patch Changes
6+
7+
- Enhanced the SocialInput component by introducing an optional keydown handler prop. This update enables custom keyboard event handling, with default behavior triggering submission on CTRL + Enter.
8+
39
## 1.0.6
410

511
### Patch Changes

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, onSubmit) => {
68+
if (event.key === 'Enter' && !event.shiftKey) {
69+
event.preventDefault()
70+
onSubmit()
71+
}
72+
}}
6673
/>
6774
)
6875
}

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { KeyboardEventHandler, forwardRef } from 'react'
3+
import { KeyboardEvent, KeyboardEventHandler, forwardRef } from 'react'
44

55
import { SocialTextField as DefaultSocialTextField } from '@baseapp-frontend/design-system/components/web/inputs'
66

@@ -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,10 +79,18 @@ 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 = (event: KeyboardEvent<HTMLDivElement>, onSubmit: VoidFunction) => {
83+
if (event.key === 'Enter' && event.ctrlKey) {
8384
event.preventDefault()
84-
form.handleSubmit(submit)(event)
85+
onSubmit()
86+
}
87+
}
88+
89+
const handleKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
90+
if (onKeyDown) {
91+
onKeyDown(event, () => form.handleSubmit(submit)(event))
92+
} else {
93+
defaultKeyDown(event, () => form.handleSubmit(submit)(event))
8594
}
8695
}
8796

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>, onSubmit: VoidFunction) => void
1819
formId?: string
1920
submit: (data: SocialUpsertForm) => void
2021
isLoading: boolean

packages/components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@baseapp-frontend/components",
33
"description": "BaseApp components modules such as comments, notifications, messages, and more.",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"sideEffects": false,
66
"scripts": {
77
"babel:bundle": "babel modules -d tmp-babel --extensions .ts,.tsx --ignore '**/__tests__/**','**/__storybook__/**'",

packages/components/schema.graphql

+5-14
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,9 @@ type ChatRoomCreatePayload {
154154
clientMutationId: String
155155
}
156156

157-
input ChatRoomDeleteMessageInput {
158-
id: ID!
159-
clientMutationId: String
160-
}
161-
162-
type ChatRoomDeleteMessagePayload {
163-
"""May contain more than one error for same field."""
164-
errors: [ErrorType]
165-
_debug: DjangoDebug
166-
deletedMessage: MessageEdge
167-
clientMutationId: String
168-
}
169-
170-
"""A Relay edge containing a `ChatRoom` and its cursor."""
157+
"""
158+
A Relay edge containing a `ChatRoom` and its cursor.
159+
"""
171160
type ChatRoomEdge {
172161
"""The item at the end of the edge"""
173162
node: ChatRoom
@@ -201,6 +190,7 @@ type ChatRoomOnMessagesCountUpdate {
201190
type ChatRoomOnRoomUpdate {
202191
room: ChatRoomEdge
203192
removedParticipants: [ChatRoomParticipant]
193+
addedParticipants: [ChatRoomParticipant]
204194
}
205195

206196
type ChatRoomParticipant implements Node {
@@ -324,6 +314,7 @@ type ChatRoomUpdatePayload {
324314
_debug: DjangoDebug
325315
room: ChatRoomEdge
326316
removedParticipants: [ChatRoomParticipant]
317+
addedParticipants: [ChatRoomParticipant]
327318
clientMutationId: String
328319
}
329320

0 commit comments

Comments
 (0)