Skip to content
Merged
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
3 changes: 3 additions & 0 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
| 'compressImageQuality'
| 'createPollOptionGap'
| 'doFileUploadRequest'
| 'focusInputOnPickerClose'
| 'handleAttachButtonPress'
| 'hasCameraPicker'
| 'hasCommands'
Expand Down Expand Up @@ -423,6 +424,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
enableSwipeToReply = true,
enforceUniqueReaction = false,
FlatList = NativeHandlers.FlatList,
focusInputOnPickerClose = true,
forceAlignMessages,
getMessageGroupStyle,
handleAttachButtonPress,
Expand Down Expand Up @@ -1651,6 +1653,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
createPollOptionGap,
doFileUploadRequest,
editMessage,
focusInputOnPickerClose,
handleAttachButtonPress,
hasCameraPicker,
hasCommands: hasCommands ?? !!clientChannelConfig?.commands?.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const useCreateInputMessageInputContext = ({
createPollOptionGap,
doFileUploadRequest,
editMessage,
focusInputOnPickerClose,
handleAttachButtonPress,
hasCameraPicker,
hasCommands,
Expand Down Expand Up @@ -49,6 +50,7 @@ export const useCreateInputMessageInputContext = ({
createPollOptionGap,
doFileUploadRequest,
editMessage,
focusInputOnPickerClose,
handleAttachButtonPress,
hasCameraPicker,
hasCommands,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,35 @@ describe('AttachButton', () => {
expect(queryByTestId('attachment-picker-list')).toBeTruthy();
});
});

it('should close the attachment picker on second press when focusInputOnPickerClose is false', async () => {
jest.spyOn(NativeHandler, 'isImageMediaLibraryAvailable').mockImplementation(() => true);

const channelProps = { channel, focusInputOnPickerClose: false };
const props = {};

renderComponent({ channelProps, client, props });

const { queryByTestId } = screen;

await waitFor(() => {
expect(queryByTestId('attach-button')).toBeTruthy();
});

act(() => {
fireEvent.press(screen.getByTestId('attach-button'));
});

await waitFor(() => {
expect(queryByTestId('attachment-picker-list')).toBeTruthy();
});

act(() => {
fireEvent.press(screen.getByTestId('attach-button'));
});

await waitFor(() => {
expect(queryByTestId('attachment-picker-list')).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,23 @@ export type AttachButtonProps = Partial<AttachButtonPropsWithContext>;
*/
export const AttachButton = (props: AttachButtonProps) => {
const { disableAttachmentPicker } = useAttachmentPickerContext();
const { inputBoxRef, handleAttachButtonPress, openAttachmentPicker } = useMessageInputContext();
const {
closeAttachmentPicker,
focusInputOnPickerClose,
handleAttachButtonPress,
inputBoxRef,
openAttachmentPicker,
} = useMessageInputContext();
const { attachmentPickerStore } = useAttachmentPickerContext();
const { selectedPicker } = useAttachmentPickerState();

const toggleAttachmentPicker = useStableCallback(() => {
if (attachmentPickerStore.state.getLatestValue().selectedPicker) {
inputBoxRef.current?.focus();
if (focusInputOnPickerClose) {
inputBoxRef.current?.focus();
} else {
closeAttachmentPicker();
}
} else {
openAttachmentPicker();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ export type InputMessageInputContextValue = {
options?: UpdateMessageOptions;
}) => ReturnType<StreamChat['updateMessage']>;

/**
* Controls what happens when the attach button is pressed while the attachment picker is open.
* When true (default), the message input is focused, toggling from the picker to the keyboard.
* When false, the attachment picker is closed without focusing the input.
* @type boolean
* @default true
*/
focusInputOnPickerClose: boolean;

/** When false, CameraSelectorIcon will be hidden */
hasCameraPicker: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useCreateMessageInputContext = ({
compressImageQuality,
createPollOptionGap,
editMessage,
focusInputOnPickerClose,
handleAttachButtonPress,
hasCameraPicker,
hasCommands,
Expand Down Expand Up @@ -61,6 +62,7 @@ export const useCreateMessageInputContext = ({
compressImageQuality,
createPollOptionGap,
editMessage,
focusInputOnPickerClose,
handleAttachButtonPress,
hasCameraPicker,
hasCommands,
Expand Down