Skip to content

Commit 20d2b61

Browse files
feat(AttachMenu): Allow disabling search input (#750)
1 parent b81ec17 commit 20d2b61

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

packages/module/src/AttachMenu/AttachMenu.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface AttachMenuProps extends DropdownProps {
2121
/** Items in menu */
2222
filteredItems: React.ReactNode;
2323
/** A callback for when the input value changes. */
24-
handleTextInputChange: (value: string) => void;
24+
handleTextInputChange?: (value: string) => void;
2525
/** Flag to indicate if menu is opened. */
2626
isOpen: boolean;
2727
/** Additional properties to pass to the Popper */
@@ -73,16 +73,18 @@ export const AttachMenu: FunctionComponent<AttachMenuProps> = ({
7373
onSelect={onSelect}
7474
{...props}
7575
>
76-
<MenuSearch {...menuSearchProps}>
77-
<MenuSearchInput {...menuSearchInputProps}>
78-
<SearchInput
79-
aria-label={searchInputAriaLabel}
80-
onChange={(_event, value) => handleTextInputChange(value)}
81-
placeholder={searchInputPlaceholder}
82-
{...searchInputProps}
83-
/>
84-
</MenuSearchInput>
85-
</MenuSearch>
76+
{handleTextInputChange && (
77+
<MenuSearch {...menuSearchProps}>
78+
<MenuSearchInput {...menuSearchInputProps}>
79+
<SearchInput
80+
aria-label={searchInputAriaLabel}
81+
onChange={(_event, value) => handleTextInputChange(value)}
82+
placeholder={searchInputPlaceholder}
83+
{...searchInputProps}
84+
/>
85+
</MenuSearchInput>
86+
</MenuSearch>
87+
)}
8688
{filteredItems}
8789
</Dropdown>
8890
);

packages/module/src/MessageBar/MessageBar.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ describe('Message bar', () => {
275275
);
276276
expect(screen.getByTestId('menu-search-input')).toBeTruthy();
277277
});
278+
it('can remove input from attach menu', async () => {
279+
render(
280+
<MessageBar
281+
onSendMessage={jest.fn}
282+
attachMenuProps={{
283+
isAttachMenuOpen: true,
284+
setIsAttachMenuOpen: jest.fn(),
285+
onAttachMenuToggleClick: jest.fn(),
286+
attachMenuItems: ATTACH_MENU_ITEMS
287+
}}
288+
/>
289+
);
290+
expect(screen.queryByRole('textbox', { name: /Filter menu items/i })).not.toBeInTheDocument();
291+
});
278292
it('can hide attach button', () => {
279293
render(<MessageBar onSendMessage={jest.fn} hasAttachButton={false} />);
280294
expect(screen.queryByRole('button', { name: 'Attach' })).toBeFalsy();

packages/module/src/MessageBar/MessageBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface MessageBarWithAttachMenuProps {
2929
/** A callback for when the attachment menu toggle is clicked */
3030
onAttachMenuToggleClick: () => void;
3131
/** A callback for when the input value in the menu changes. */
32-
onAttachMenuInputChange: (value: string) => void;
32+
onAttachMenuInputChange?: (value: string) => void;
3333
/** Function callback called when user selects item in menu. */
3434
onAttachMenuSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void;
3535
/** Placeholder for search input */

0 commit comments

Comments
 (0)