Skip to content

Commit

Permalink
fix(accessibility): Add accessible name for ReplyField (#704)
Browse files Browse the repository at this point in the history
* fix(accessibility): Add accessible name for ReplyField

* fix(tests): Fix unit tests

* fix(tests): Fix lint
  • Loading branch information
bkepka-box authored Sep 21, 2023
1 parent 34b49ab commit 97fbfb8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ba.annotationsPost = Post
ba.annotationsSave = Save
# Aria label description for reply popup
ba.popup.reply.comment = Comment
# Aria label description for annotation comment field
ba.popup.reply.field = Type a comment
# Button label for cancelling the creation of a description, comment, or reply
ba.popups.cancel = Cancel
# Button label for adding a comment in the drawing toolbar
Expand Down
5 changes: 5 additions & 0 deletions src/components/Popups/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export default defineMessages({
description: 'Aria label description for reply popup',
defaultMessage: 'Comment',
},
ariaLabelReplyField: {
id: 'ba.popup.reply.field',
description: 'Aria label description for annotation comment field',
defaultMessage: 'Type a comment',
},
buttonCancel: {
id: 'ba.popups.cancel',
description: 'Button label for cancelling the creation of a description, comment, or reply',
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReplyField/ReplyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
getActiveMentionForEditorState,
} from 'box-ui-elements/es/components/form-elements/draft-js-mention-selector/utils';
import { DraftHandleValue, Editor, EditorState } from 'draft-js';
import { IntlShape } from 'react-intl';
import PopupList from '../Popups/PopupList';
import { Collaborator } from '../../@types';
import messages from '../Popups/messages';
import { VirtualElement } from '../Popups/Popper';
import './ReplyField.scss';

Expand All @@ -29,6 +31,7 @@ export type Props = {
onChange: (editorState: EditorState) => void;
placeholder?: string;
setCursorPosition: (cursorPosition: number) => void;
intl: IntlShape;
};

export type State = {
Expand Down Expand Up @@ -197,13 +200,14 @@ export default class ReplyField extends React.Component<Props, State> {
handleMouseDown = (event: React.SyntheticEvent): void => event.preventDefault(); // prevent the blur event so that Editor can remain focus

render(): JSX.Element {
const { className, collaborators, editorState, isDisabled, placeholder, ...rest } = this.props;
const { className, collaborators, intl, editorState, isDisabled, placeholder, ...rest } = this.props;
const { activeItemIndex, popupAutoScroll, popupReference } = this.state;

return (
<div className={classnames(className, 'ba-ReplyField')}>
<Editor
{...rest}
ariaLabel={intl.formatMessage(messages.ariaLabelReplyField)}
ariaMultiline
editorState={editorState}
handleReturn={this.handleReturn}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ReplyField/__tests__/ReplyField-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { getActiveMentionForEditorState } from 'box-ui-elements/es/components/form-elements/draft-js-mention-selector/utils';
import { shallow, ShallowWrapper } from 'enzyme';
import { Editor, EditorState } from 'draft-js';
import { IntlShape, MessageDescriptor } from 'react-intl';
import PopupList from '../../Popups/PopupList';
import ReplyField, { Props, State } from '../ReplyField';
import { VirtualElement } from '../../Popups/Popper';
Expand All @@ -28,6 +29,9 @@ jest.mock('lodash/debounce', () => (func: Function) => func);
describe('ReplyField', () => {
const defaults: Props = {
className: 'ba-Popup-field',
intl: {
formatMessage: (message: MessageDescriptor) => message,
} as IntlShape,
collaborators: [
{ id: 'testid1', name: 'test1', item: { id: 'testid1', name: 'test1', type: 'user' } },
{ id: 'testid2', name: 'test2', item: { id: 'testid2', name: 'test2', type: 'user' } },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { EditorState } from 'draft-js';
import { mount, ReactWrapper } from 'enzyme';
import { IntlShape } from 'react-intl';
import ReplyField from '../ReplyField';
import ReplyFieldContainer, { Props } from '../ReplyFieldContainer';
import { createStore } from '../../../store';
Expand All @@ -17,6 +18,7 @@ describe('ReplyFieldContainer', () => {
editorState: EditorState.createEmpty(),
onChange: jest.fn(),
onClick: jest.fn(),
intl: {} as IntlShape,
store,
};

Expand Down
1 change: 1 addition & 0 deletions src/components/ReplyForm/ReplyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const ReplyForm = (props: Props): JSX.Element => {
className="ba-Popup-field"
data-testid="ba-Popup-field"
editorState={editorState}
intl={intl}
isDisabled={isPending}
onChange={handleChange}
placeholder={intl.formatMessage(messages.fieldPlaceholder)}
Expand Down

0 comments on commit 97fbfb8

Please sign in to comment.