-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiSkipLink] Add
fallbackDestination
support, defaulting to main
…
… tag (#6261) * Solidify EuiSkipLink as always being an `a` tag - remove PropsForButton/ExclusiveUnion typing - always pass a `href`, even if it's just `href="#"` - simplify optionalProps to just being an optional onClick * Add support for `fallbackDestination` query selectors, defaulting to the `main` tag * [setup] Convert all render tests to RTL * Add unit tests for fallbackDestination * [docs] improve skip link docs - remove callout about skip link not working on our doc - remove isFixed toggle, since our docs now have a skip link - make example work even in codesandbox, and add example with `main` fallback behavior * Fix custom `onClick`s overriding ours instead of being called after * [perf] optimize onClick to a memoized callback, and fix consumer onClick to always be called * changelog
- Loading branch information
Constance
authored
Sep 23, 2022
1 parent
08c4ac4
commit b4ef328
Showing
6 changed files
with
144 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
import React, { useState } from 'react'; | ||
import React from 'react'; | ||
|
||
import { | ||
EuiSkipLink, | ||
EuiCallOut, | ||
EuiSpacer, | ||
EuiSwitch, | ||
} from '../../../../src/components'; | ||
import { EuiSkipLink, EuiText } from '../../../../src/components'; | ||
|
||
export default () => { | ||
const [isFixed, setFixed] = useState(false); | ||
|
||
return ( | ||
<> | ||
<EuiSwitch | ||
label="Fix link to top of screen" | ||
checked={isFixed} | ||
onChange={(e) => setFixed(e.target.checked)} | ||
/> | ||
<EuiSpacer /> | ||
<EuiSkipLink | ||
destinationId="/utilities/accessibility" | ||
position={isFixed ? 'fixed' : 'static'} | ||
data-test-subj="skip-link-demo-subj" | ||
> | ||
Skip to {isFixed && 'main '}content | ||
<EuiText id="skip-link-example"> | ||
<p>The following skip links are only visible on focus:</p> | ||
<EuiSkipLink destinationId="skip-link-example" overrideLinkBehavior> | ||
Skips to this example container | ||
</EuiSkipLink> | ||
<EuiSkipLink destinationId="" overrideLinkBehavior> | ||
Falls back to main container | ||
</EuiSkipLink> | ||
{isFixed && ( | ||
<> | ||
<EuiCallOut | ||
size="s" | ||
title="A functional ‘Skip to main content’ link will be added to the EUI docs site once our URL format is updated." | ||
iconType="iInCircle" | ||
/> | ||
</> | ||
)} | ||
</> | ||
</EuiText> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- Added the `fallbackDestination` prop to `EuiSkipLink`, which accepts a string of query selectors to fall back to if the `destinationId` does not have a valid target. Defaults to `main` | ||
- `EuiSkipLink` is now always an `a` tag to ensure that it is always placed within screen reader link menus. | ||
|
||
**Bug fixes** | ||
|
||
- Fixed custom `onClick`s passed to `EuiSkipLink` overriding `overrideLinkBehavior` |