Skip to content

Commit

Permalink
feat: Improve support for accessibility with aria label section
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Oct 2, 2024
1 parent 55d3818 commit 9a97e4d
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

**Added:**
- Added proper support for React 19!
- Added a new `ariaLabel` section to improve accessibility support
- Added a new `useChatHistory` hook that provides 3 new actions (`showChatHistory`, `getHistoryMessages` and `setHistoryMessages`)
- Added a new `sendButtonDisabledStyle` (send button is now properly disabled when textarea is disabled as well)
- Improved localised styling of chatbots to reduce conflicts with host websites (and with other chatbots)

**Note:**
This update brings about a couple of fantastic improvements - drastically reduced library size (by nearly 60%), React 19 support and improved localised styles!
This update brings about a couple of fantastic improvements - drastically reduced library size (by nearly 60%), React 19 support, improved localised styles and better accessibility support!

## v2.0.0-beta.13 (26-09-2024)

Expand Down
2 changes: 2 additions & 0 deletions src/components/Buttons/AudioButton/AudioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const AudioButton = () => {

return (
<div
aria-label={settings.ariaLabel?.audioButton ?? "toggle audio"}
role="button"
onMouseDown={(event: MouseEvent) => {
event.preventDefault();
toggleAudio();
Expand Down
2 changes: 2 additions & 0 deletions src/components/Buttons/CloseChatButton/CloseChatButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const CloseChatButton = () => {

return (
<div
aria-label={settings.ariaLabel?.closeChatButton ?? "close chat"}
role="button"
onMouseDown={(event: MouseEvent) => {
event.stopPropagation();
openChat(false);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Buttons/EmojiButton/EmojiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ const EmojiButton = () => {
return (
<>
<div
aria-label={settings.ariaLabel?.emojiButton ?? "emoji picker"}
role="button"
ref={iconContainerRef}
className={`${textAreaDisabled ? "rcb-emoji-button-disabled" : "rcb-emoji-button-enabled"}`}
style={textAreaDisabled ? emojiButtonDisabledStyle : styles.emojiButtonStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const FileAttachmentButton = () => {
<>
{blockAllowsAttachment ? (
<label
aria-label={settings.ariaLabel?.fileAttachmentButton ?? "upload file"}
role="button"
className="rcb-attach-button-enabled"
style={styles.fileAttachmentButtonStyle}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const NotificationButton = () => {

return (
<div
aria-label={settings.ariaLabel?.notificationButton ?? "toggle notifications"}
role="button"
onMouseDown={(event: MouseEvent) => {
event.preventDefault();
toggleNotifications();
Expand Down
2 changes: 2 additions & 0 deletions src/components/Buttons/SendButton/SendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const SendButton = () => {

return (
<div
aria-label={settings.ariaLabel?.sendButton ?? "send message"}
role="button"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onMouseDown={async (event: MouseEvent) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Buttons/VoiceButton/VoiceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const VoiceButton = () => {

return (
<div
aria-label={settings.ariaLabel?.voiceButton ?? "toggle voice"}
role="button"
onMouseDown={(event: MouseEvent) => {
event.preventDefault();
if (textAreaDisabled) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/ChatBotButton/ChatBotButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const ChatBotButton = () => {
<>
{!settings.general?.embedded &&
<div
aria-label="Open Chat"
aria-label={settings.ariaLabel?.chatButton ?? "open chat"}
role="button"
style={chatButtonStyle}
className={`rcb-toggle-button ${isChatWindowOpen ? "rcb-button-hide" : "rcb-button-show"}`}
onClick={toggleChatWindow}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ChatBotInput/ChatBotInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ const ChatBotInput = ({ buttons }: { buttons: JSX.Element[] }) => {

return (
<div
aria-label={settings.ariaLabel?.inputTextArea ?? "input text area"}
role="textbox"
onMouseDown={(event: MouseEvent) => {
event.stopPropagation();
// checks if user is interacting with chatbot for the first time
Expand Down
11 changes: 11 additions & 0 deletions src/constants/internal/DefaultSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,16 @@ export const DefaultSettings: Settings = {
rcbUserSubmitText: false,
rcbUserUploadFile: false,
rcbTextAreaChangeValue: false,
},
ariaLabel: {
chatButton: "open chat",
audioButton: "toggle audio",
closeChatButton: "close chat",
emojiButton: "emoji picker",
fileAttachmentButton: "upload file",
notificationButton: "toggle notifications",
sendButton: "send message",
voiceButton: "toggle voice",
inputTextArea: "input text area",
}
}
11 changes: 11 additions & 0 deletions src/types/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,16 @@ export type Settings = {
rcbUserSubmitText?: boolean;
rcbUserUploadFile?: boolean;
rcbTextAreaChangeValue?: boolean;
},
ariaLabel?: {
chatButton?: string;
audioButton?: string;
closeChatButton?: string;
emojiButton?: string;
fileAttachmentButton?: string;
notificationButton?: string;
sendButton?: string;
voiceButton?: string;
inputTextArea?: string;
}
}

0 comments on commit 9a97e4d

Please sign in to comment.