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

Add closeButtonLabel to flyout #1031

Merged
merged 5 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `3.1.0`.
- Added `closeButtonAriaLabel` property to `EuiFlyout` ([#1031](https://github.com/elastic/eui/pull/1031))

## [`3.1.0`](https://github.com/elastic/eui/tree/v3.1.0)

Expand Down
20 changes: 17 additions & 3 deletions src/components/flyout/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ export class EuiFlyout extends Component {
};

render() {
const { className, children, hideCloseButton, onClose, ownFocus, size, ...rest } = this.props;
const {
className,
children,
hideCloseButton,
onClose,
ownFocus,
size,
closeButtonAriaLabel,
...rest
} = this.props;

const classes = classnames('euiFlyout', sizeToClassNameMap[size], className);

Expand All @@ -37,7 +46,7 @@ export class EuiFlyout extends Component {
className="euiFlyout__closeButton"
iconType="cross"
color="text"
aria-label="Closes this dialog"
aria-label={closeButtonAriaLabel}
onClick={onClose}
data-test-subj="euiFlyoutCloseButton"
/>
Expand Down Expand Up @@ -71,7 +80,7 @@ export class EuiFlyout extends Component {
<span>
{optionalOverlay}
{/* Trap focus even when ownFocus={false}, otherwise closing the flyout won't return focus
to the originating button */}
to the originating button */}
<FocusTrap
focusTrapOptions={{
fallbackFocus: () => this.flyout,
Expand All @@ -98,10 +107,15 @@ EuiFlyout.propTypes = {
* Locks the mouse / keyboard focus to within the flyout
*/
ownFocus: PropTypes.bool,
/**
* Specify an aria-label for the close button of the flyout
*/
closeButtonAriaLabel: PropTypes.string,
};

EuiFlyout.defaultProps = {
size: 'm',
hideCloseButton: false,
ownFocus: false,
closeButtonAriaLabel: 'Closes this dialog',
};
24 changes: 24 additions & 0 deletions src/components/flyout/flyout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,32 @@ describe('EuiFlyout', () => {
expect(component)
.toMatchSnapshot();
});

describe('closeButtonLabel', () => {
test('has a default label for the close button', () => {
const component = render(
<EuiFlyout
onClose={() => {}}
/>
);
const label = component.find('[data-test-subj="euiFlyoutCloseButton"]').prop('aria-label');
expect(label).toBe('Closes this dialog');
});

test('sets a custom label for the close button', () => {
const component = render(
<EuiFlyout
onClose={() => {}}
closeButtonAriaLabel="Closes specific flyout"
/>
);
const label = component.find('[data-test-subj="euiFlyoutCloseButton"]').prop('aria-label');
expect(label).toBe('Closes specific flyout');
});
});
});


describe('size', () => {
SIZES.forEach(size => {
it(`${size} is rendered`, () => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/flyout/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ declare module '@elastic/eui' {
* Locks the mouse / keyboard focus to within the flyout
*/
ownFocus?: boolean;
/**
* Specify an aria-label for the close button of the flyout.
*/
closeButtonAriaLabel?: string;
}

export const EuiFlyout: React.SFC<
Expand All @@ -25,4 +29,4 @@ declare module '@elastic/eui' {
export const EuiFlyoutHeader: React.SFC<CommonProps & EuiFlyoutHeaderProps>;

export const EuiFlyoutFooter: React.SFC<CommonProps>;
}
}