-
Notifications
You must be signed in to change notification settings - Fork 842
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
|
@@ -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" | ||
/> | ||
|
@@ -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, | ||
|
@@ -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. | ||
*/ | ||
closeButtonLabel: PropTypes.string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other option is to start a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with |
||
}; | ||
|
||
EuiFlyout.defaultProps = { | ||
size: 'm', | ||
hideCloseButton: false, | ||
ownFocus: false, | ||
closeButtonLabel: 'Closes this dialog', | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this test read as 'has a custom label for close button'? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`, () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No period necessary here