Skip to content
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

Added aria-describedby to EuiFilePicker #2919

Merged
merged 9 commits into from
Feb 26, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added default prompt text to `aria-describedby` for `EuiFilePicker` ([#2919](https://github.com/elastic/eui/pull/2919))
- Added SASS variables for text variants of the primary palette `$euiColorPrimaryText`, `$euiColorSecondaryText`, etc... Updated components to use these new variables. ([#2873](https://github.com/elastic/eui/pull/2873))
- Updated SASS mixin `makeHighContrastColor()` to default `$background: $euiPageBackgroundColor` and `$ratio: 4.5`. Created `makeGraphicContrastColor()` for graphic specific contrast levels of 3.0. ([#2873](https://github.com/elastic/eui/pull/2873))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ exports[`EuiFilePicker is rendered 1`] = `
class="euiFilePicker__wrap"
>
<input
aria-describedby="htmlId"
aria-label="aria-label"
class="euiFilePicker__input"
data-test-subj="test subject string"
type="file"
/>
<div
class="euiFilePicker__prompt"
id="htmlId"
>
<div
aria-hidden="true"
Expand Down
5 changes: 5 additions & 0 deletions src/components/form/file_picker/file_picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { requiredProps } from '../../../test';

import { EuiFilePicker } from './file_picker';

// Mock the htmlIdGenerator to generate predictable ids for snapshot tests
jest.mock('../../../services/accessibility/html_id_generator', () => ({
htmlIdGenerator: () => () => 'htmlId',
}));

describe('EuiFilePicker', () => {
test('is rendered', () => {
const component = render(<EuiFilePicker {...requiredProps} />);
Expand Down
10 changes: 9 additions & 1 deletion src/components/form/file_picker/file_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiProgress } from '../../progress';
import { EuiIcon } from '../../icon';
import { EuiI18n } from '../../i18n';
import { EuiLoadingSpinner } from '../../loading';
import { htmlIdGenerator } from '../../../services/accessibility/html_id_generator';

const displayToClassNameMap = {
default: null,
Expand Down Expand Up @@ -127,6 +128,12 @@ export class EuiFilePicker extends Component<EuiFilePickerProps> {
...rest
} = this.props;

let promptId: string = htmlIdGenerator()();

if (id) {
promptId = `${id}-filePicker__prompt`;
}

const isOverridingInitialPrompt = this.state.promptText != null;

const normalFormControl = display === 'default';
Expand Down Expand Up @@ -198,10 +205,11 @@ export class EuiFilePicker extends Component<EuiFilePickerProps> {
onDragLeave={this.hideDrop}
onDrop={this.hideDrop}
disabled={disabled}
aria-describedby={promptId}
{...rest}
/>
</EuiValidatableControl>
<div className="euiFilePicker__prompt">
<div className="euiFilePicker__prompt" id={promptId}>
<EuiIcon
className="euiFilePicker__icon"
type="importAction"
Expand Down