Skip to content

Commit 819ecfa

Browse files
fix(ChatbotConversationHistoryNav): Allow passing custom ids to dropdowns (#628)
* fix(ChatbotConversationHistoryNav): Allow passing custom ids to dropdowns Also updating pin/unpin demo so dropdown is focused when a change is made. Co-authored-by: Eric Olkowski <[email protected]>
1 parent 9e4b619 commit 819ecfa

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
9797
}
9898
return newPinned;
9999
});
100+
101+
// Focus the conversation input after pin/unpin action
102+
setTimeout(() => {
103+
const dropdown = document.getElementById(`pin-demo-${conversationId}-dropdown`);
104+
if (dropdown) {
105+
dropdown.focus();
106+
}
107+
}, 100);
100108
};
101109

102110
const createMenuItems = (conversationId: string) => {
@@ -136,7 +144,8 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
136144
pinnedItems.push({
137145
...conv,
138146
menuItems: createMenuItems(conv.id),
139-
icon: <ThumbtackIcon />
147+
icon: <ThumbtackIcon />,
148+
dropdownId: `pin-demo-${conv.id}-dropdown`
140149
});
141150
}
142151
});
@@ -153,7 +162,8 @@ export const ChatbotHeaderPinDemo: FunctionComponent = () => {
153162
.filter((conv) => !pinnedConversations.has(conv.id))
154163
.map((conv) => ({
155164
...conv,
156-
menuItems: createMenuItems(conv.id)
165+
menuItems: createMenuItems(conv.id),
166+
dropdownId: `pin-demo-${conv.id}-dropdown`
157167
}));
158168

159169
if (unpinnedConversations.length > 0) {

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ export interface ChatbotConversationHistoryDropdownProps extends Omit<DropdownPr
1919
label?: string;
2020
/** Callback for when user selects item. */
2121
onSelect?: (event?: React.MouseEvent, value?: string | number) => void;
22+
/** Id applied to dropdown menu toggle */
23+
id?: string;
2224
}
2325

2426
export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConversationHistoryDropdownProps> = ({
2527
menuItems,
2628
menuClassName,
2729
onSelect,
28-
label
30+
label,
31+
id
2932
}: ChatbotConversationHistoryDropdownProps) => {
3033
const [isOpen, setIsOpen] = useState(false);
3134

@@ -44,6 +47,7 @@ export const ChatbotConversationHistoryDropdown: FunctionComponent<ChatbotConver
4447
ref={toggleRef}
4548
isExpanded={isOpen}
4649
onClick={() => setIsOpen(!isOpen)}
50+
id={id}
4751
>
4852
<EllipsisIcon />
4953
</MenuToggle>

packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export interface Conversation {
6565
additionalProps?: ButtonProps;
6666
/** Additional props passed to conversation list item */
6767
listItemProps?: Omit<ListItemProps, 'children'>;
68+
/** Custom dropdown ID to ensure uniqueness across demo instances */
69+
dropdownId?: string;
6870
}
6971
export interface ChatbotConversationHistoryNavProps extends DrawerProps {
7072
/** Function called to toggle drawer */
@@ -202,6 +204,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
202204
onSelect={conversation.onSelect}
203205
menuItems={conversation.menuItems}
204206
label={conversation.label}
207+
id={conversation.dropdownId}
205208
/>
206209
)}
207210
</>

0 commit comments

Comments
 (0)