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 2 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 `closeButtonLabel` 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,
closeButtonLabel,
...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={closeButtonLabel}
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No period necessary here

*/
closeButtonLabel: PropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this to closeButtonAriaLabel so that it's absolutely clear by the prop name itself what the "label" is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option is to start a closeButtonProps object to handle more than just the aria-label.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with closeButtonAriaLabel, since I think if we allow overwriting everything on the button, consumers might be able to mess around too much with the close button as it is.

};

EuiFlyout.defaultProps = {
size: 'm',
hideCloseButton: false,
ownFocus: false,
closeButtonLabel: '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('has a default label for the close button', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test read as 'has a custom label for close button'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course... copy-paste-error :D

const component = render(
<EuiFlyout
onClose={() => {}}
closeButtonLabel="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.
*/
closeButtonLabel?: 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>;
}
}