diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e649171278..2b5c8dce98d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ **Bug fixes** - Fixed `EuiContextMenu` panel `onAnimationEnd` transition bug in Chrome ([#3656](https://github.com/elastic/eui/pull/3656)) +- Fixed `EuiSkipLink` interactive props and Safari click issue ([#3665](https://github.com/elastic/eui/pull/3665)) ## [`26.1.0`](https://github.com/elastic/eui/tree/v26.1.0) diff --git a/src-docs/src/views/accessibility/skip_link.js b/src-docs/src/views/accessibility/skip_link.js index 15cf70e03c1..90dd813c8b7 100644 --- a/src-docs/src/views/accessibility/skip_link.js +++ b/src-docs/src/views/accessibility/skip_link.js @@ -1,16 +1,18 @@ -import React, { Fragment, useState } from 'react'; +import React, { useState } from 'react'; -import { EuiSkipLink } from '../../../../src/components/accessibility/skip_link'; -import { EuiCallOut } from '../../../../src/components/call_out'; -import { EuiText } from '../../../../src/components/text'; -import { EuiSpacer } from '../../../../src/components/spacer'; -import { EuiSwitch } from '../../../../src/components/form/switch'; +import { + EuiSkipLink, + EuiCallOut, + EuiText, + EuiSpacer, + EuiSwitch, +} from '../../../../src/components'; export default () => { const [isFixed, setFixed] = useState(false); return ( - + <> {isFixed ? (

@@ -36,26 +38,21 @@ export default () => { onChange={e => setFixed(e.target.checked)} /> - {isFixed ? ( - - - Skip to main content - + + Skip to {isFixed && 'main '}content + + {isFixed && ( + <> - - ) : ( - - Skip to content - + )} - + ); }; diff --git a/src/components/accessibility/__snapshots__/skip_link.test.tsx.snap b/src/components/accessibility/__snapshots__/skip_link.test.tsx.snap index 685870e4087..8d73fa7dd02 100644 --- a/src/components/accessibility/__snapshots__/skip_link.test.tsx.snap +++ b/src/components/accessibility/__snapshots__/skip_link.test.tsx.snap @@ -7,6 +7,24 @@ exports[`EuiSkipLink is rendered 1`] = ` data-test-subj="test subject string" href="#somewhere" rel="noreferrer" +> + + + Skip + + + +`; + +exports[`EuiSkipLink props onClick is rendered 1`] = ` + `; -exports[`EuiSkipLink position absolute is rendered 1`] = ` +exports[`EuiSkipLink props position absolute is rendered 1`] = ` `; -exports[`EuiSkipLink position fixed is rendered 1`] = ` +exports[`EuiSkipLink props position fixed is rendered 1`] = ` `; -exports[`EuiSkipLink position static is rendered 1`] = ` +exports[`EuiSkipLink props position static is rendered 1`] = ` + + + + + +`; + +exports[`EuiSkipLink props tabIndex is rendered 1`] = ` { test('is rendered', () => { const component = render( - + + Skip + ); expect(component).toMatchSnapshot(); }); - describe('position', () => { - POSITIONS.forEach(position => { - test(`${position} is rendered`, () => { - const component = render( - - ); + describe('props', () => { + test('tabIndex is rendered', () => { + const component = render( + + ); - expect(component).toMatchSnapshot(); + expect(component).toMatchSnapshot(); + }); + + test('onClick is rendered', () => { + const component = render( + {}} /> + ); + + expect(component).toMatchSnapshot(); + }); + + describe('position', () => { + POSITIONS.forEach(position => { + test(`${position} is rendered`, () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); }); }); }); diff --git a/src/components/accessibility/skip_link.tsx b/src/components/accessibility/skip_link.tsx index 7cb97b2f662..0c2b2fca4c6 100644 --- a/src/components/accessibility/skip_link.tsx +++ b/src/components/accessibility/skip_link.tsx @@ -26,36 +26,38 @@ import { PropsForAnchor, PropsForButton, ExclusiveUnion } from '../common'; type Positions = 'static' | 'fixed' | 'absolute'; export const POSITIONS = ['static', 'fixed', 'absolute'] as Positions[]; -export interface EuiSkipLinkProps extends EuiButtonProps { +interface EuiSkipLinkInterface extends EuiButtonProps { /** - * If true, the link will be fixed to the top left of the viewport + * Change the display position of the element when focused. + * If 'fixed', the link will be fixed to the top left of the viewport */ position?: Positions; - /** * Typically an anchor id (e.g. `a11yMainContent`), the value provided * will be prepended with a hash `#` and used as the link `href` */ destinationId: string; - + /** + * When position is fixed, this is forced to `0` + */ tabIndex?: number; } type propsForAnchor = PropsForAnchor< - EuiSkipLinkProps, + EuiSkipLinkInterface, { buttonRef?: Ref; } >; type propsForButton = PropsForButton< - EuiSkipLinkProps, + EuiSkipLinkInterface, { buttonRef?: Ref; } >; -export type Props = ExclusiveUnion; +export type EuiSkipLinkProps = ExclusiveUnion; export const EuiSkipLink: FunctionComponent = ({ destinationId, @@ -71,14 +73,22 @@ export const EuiSkipLink: FunctionComponent = ({ className ); + // Create the `href` from `destinationId` + let optionalProps = {}; + if (destinationId) { + optionalProps = { + href: `#${destinationId}`, + }; + } + return ( {children}