Skip to content

Commit b2bd721

Browse files
committed
fix(ChatbotConversationHistoryNav): Allow additional props on dropdown
Dropdown did not accept additional props like id, etc. This made it difficult to add things like custom focus. This allows props to be passed down to the tooltip, toggle, and dropdown. Also updated pin demo to show focus functionality.
1 parent 69fd947 commit b2bd721

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

packages/module/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerWithPin.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
4040
const [pinnedConversations, setPinnedConversations] = useState<Set<string>>(new Set());
4141
const displayMode = ChatbotDisplayMode.embedded;
4242

43+
const focusItem = (conversationId: string) => {
44+
setTimeout(() => {
45+
document.getElementById(`conversation-options-${conversationId}`)?.focus();
46+
}, 100);
47+
};
48+
4349
const handlePinToggle = (conversationId: string) => {
4450
setPinnedConversations((prev) => {
4551
const newPinned = new Set(prev);
4652
if (newPinned.has(conversationId)) {
4753
newPinned.delete(conversationId);
54+
focusItem(conversationId);
4855
} else {
4956
newPinned.add(conversationId);
57+
focusItem(conversationId);
5058
}
5159
return newPinned;
5260
});
@@ -88,8 +96,10 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
8896
if (pinnedConversations.has(conv.id)) {
8997
pinnedItems.push({
9098
...conv,
99+
label: `Conversation options for ${conv.text}`,
91100
menuItems: createMenuItems(conv.id),
92-
icon: <ThumbtackIcon />
101+
icon: <ThumbtackIcon />,
102+
toggleProps: { id: `conversation-options-${conv.id}` }
93103
});
94104
}
95105
});
@@ -106,7 +116,9 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
106116
.filter((conv) => !pinnedConversations.has(conv.id))
107117
.map((conv) => ({
108118
...conv,
109-
menuItems: createMenuItems(conv.id)
119+
label: `Conversation options for ${conv.text}`,
120+
menuItems: createMenuItems(conv.id),
121+
toggleProps: { id: `conversation-options-${conv.id}` }
110122
}));
111123

112124
if (unpinnedConversations.length > 0) {

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
// ============================================================================
22
// Chatbot Header - Chatbot Conversation History Nav
33
// ============================================================================
4-
import type { MouseEvent, FunctionComponent, Ref } from 'react';
4+
import type { FunctionComponent, Ref } from 'react';
55

66
import { useState } from 'react';
77

88
// Import PatternFly components
9-
import { MenuToggleElement, Tooltip, MenuToggle, Dropdown, DropdownProps } from '@patternfly/react-core';
9+
import {
10+
MenuToggleElement,
11+
Tooltip,
12+
MenuToggle,
13+
Dropdown,
14+
DropdownProps,
15+
MenuToggleProps,
16+
TooltipProps
17+
} from '@patternfly/react-core';
1018

1119
import EllipsisIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
1220

@@ -19,13 +27,22 @@ export interface ChatbotConversationHistoryDropdownProps extends Omit<DropdownPr
1927
label?: string;
2028
/** Callback for when user selects item. */
2129
onSelect?: (event?: React.MouseEvent, value?: string | number) => void;
30+
/** Additional props passed down to toggle component */
31+
toggleProps?: MenuToggleProps;
32+
/** Additional props passed down to tooltip component */
33+
tooltipProps?: TooltipProps;
34+
/** Additional props passed down to dropdown component */
35+
dropdownProps?: DropdownProps;
2236
}
2337

2438
export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConversationHistoryDropdownProps> = ({
2539
menuItems,
2640
menuClassName,
2741
onSelect,
28-
label
42+
label,
43+
tooltipProps,
44+
toggleProps,
45+
dropdownProps
2946
}: ChatbotConversationHistoryDropdownProps) => {
3047
const [isOpen, setIsOpen] = useState(false);
3148

@@ -36,6 +53,7 @@ export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConver
3653
position="bottom"
3754
// prevents VO announcements of both aria label and tooltip
3855
aria="none"
56+
{...tooltipProps}
3957
>
4058
<MenuToggle
4159
className="pf-chatbot__history-actions"
@@ -45,6 +63,7 @@ export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConver
4563
isExpanded={isOpen}
4664
onClick={() => setIsOpen(!isOpen)}
4765
role="menuitem"
66+
{...toggleProps}
4867
>
4968
<EllipsisIcon />
5069
</MenuToggle>
@@ -64,6 +83,7 @@ export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConver
6483
shouldFocusToggleOnSelect
6584
shouldFocusFirstItemOnOpen
6685
toggle={toggle}
86+
{...dropdownProps}
6787
>
6888
{menuItems}
6989
</Dropdown>

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import {
3232
DrawerActionsProps,
3333
DrawerCloseButtonProps,
3434
DrawerPanelBodyProps,
35-
SkeletonProps
35+
SkeletonProps,
36+
MenuToggleProps,
37+
TooltipProps,
38+
DropdownProps
3639
} from '@patternfly/react-core';
3740

3841
import { OutlinedCommentAltIcon } from '@patternfly/react-icons';
@@ -60,6 +63,12 @@ export interface Conversation {
6063
onSelect?: (event?: React.MouseEvent, value?: string | number) => void;
6164
/** Additional props passed to conversation menu item */
6265
additionalProps?: MenuItemProps;
66+
/** Additional props passed down to toggle component */
67+
toggleProps?: MenuToggleProps;
68+
/** Additional props passed down to tooltip component */
69+
tooltipProps?: TooltipProps;
70+
/** Additional props passed down to dropdown component */
71+
dropdownProps?: DropdownProps;
6372
}
6473
export interface ChatbotConversationHistoryNavProps extends DrawerProps {
6574
/** Function called to toggle drawer */
@@ -175,6 +184,9 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
175184
onSelect={conversation.onSelect}
176185
menuItems={conversation.menuItems}
177186
label={conversation.label}
187+
toggleProps={conversation.toggleProps}
188+
tooltipProps={conversation.tooltipProps}
189+
dropdownProps={conversation.dropdownProps}
178190
/>
179191
)
180192
}

0 commit comments

Comments
 (0)