-
Notifications
You must be signed in to change notification settings - Fork 36
fix(various): IFD accessibility call-outs #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useState, FunctionComponent } from 'react'; | ||
| import { useState, useEffect, useRef, FunctionComponent } from 'react'; | ||
| import { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot'; | ||
| import ChatbotConversationHistoryNav, { | ||
| Conversation | ||
|
|
@@ -71,8 +71,28 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => { | |
| const [hasError, setHasError] = useState(false); | ||
| const [isEmpty, setIsEmpty] = useState(false); | ||
| const [hasNoResults, setHasNoResults] = useState(false); | ||
| const [announcement, setAnnouncement] = useState(''); | ||
| const [debouncedAnnouncement, setDebouncedAnnouncement] = useState(''); | ||
| const announcementTimeoutRef = useRef<NodeJS.Timeout>(); | ||
| const displayMode = ChatbotDisplayMode.embedded; | ||
|
|
||
| // Debounce announcement updates to prevent screen reader overload | ||
| useEffect(() => { | ||
| if (announcementTimeoutRef.current) { | ||
| clearTimeout(announcementTimeoutRef.current); | ||
| } | ||
|
|
||
| announcementTimeoutRef.current = setTimeout(() => { | ||
| setDebouncedAnnouncement(announcement); | ||
| }, 500); | ||
|
|
||
| return () => { | ||
| if (announcementTimeoutRef.current) { | ||
| clearTimeout(announcementTimeoutRef.current); | ||
| } | ||
| }; | ||
| }, [announcement]); | ||
|
|
||
| const findMatchingItems = (targetValue: string) => { | ||
| const filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => { | ||
| const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase())); | ||
|
|
@@ -168,12 +188,23 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => { | |
| handleTextInputChange={(value: string) => { | ||
| if (value === '') { | ||
| setConversations(initialConversations); | ||
| setAnnouncement(''); | ||
| setDebouncedAnnouncement(''); | ||
| setHasNoResults(false); | ||
| } else { | ||
| // this is where you would perform search on the items in the drawer | ||
| // and update the state | ||
| const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value); | ||
| const totalCount = Object.values(newConversations).flat().length; | ||
| const newAnnouncement = | ||
| totalCount === 1 | ||
| ? `${totalCount} conversation matches "${value}"` | ||
| : `${totalCount} conversations match "${value}"`; | ||
| setAnnouncement(newAnnouncement); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More of a nit since it's example code, but it might be good to maybe have a debounce when setting this announcement text. Granted it may be due to the dual live regions in the component code as well, but when trying to search "red" in the example, VO stops to tell me the results for just "r"
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gave this a go! Let me know what you think. |
||
| setConversations(newConversations); | ||
| } | ||
| // this is where you would perform search on the items in the drawer | ||
| // and update the state | ||
| const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value); | ||
| setConversations(newConversations); | ||
| }} | ||
| searchInputScreenReaderText={debouncedAnnouncement} | ||
| drawerContent={<div>Drawer content</div>} | ||
| isLoading={isLoading} | ||
| errorState={hasError ? ERROR : undefined} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.