-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): Add onClick to SkipToContent in demos (#11297)
* chore(docs): Add onClick to SkipToContent in demos SkipToContent does not work in the context of the PatternFly page. Using document.getElementById sidesteps this issue and allows them to work as usual. I tried using refs, but because Page is an older class component, the refs were not compatible. We'd likely need to rewrite page as a function component. This is good enough for now, in my opinion. SkipToContentBasic works as advertised, so I am not touching that, and I also did not touch react-integration or unit tests. * chore(SkipToContent): Update demo Use refs in demo to match other demos.
- Loading branch information
1 parent
9206fc5
commit 6411961
Showing
22 changed files
with
430 additions
and
273 deletions.
There are no files selected for viewing
270 changes: 144 additions & 126 deletions
270
packages/react-core/src/components/SkipToContent/examples/SkipToContentBasic.tsx
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,128 +1,146 @@ | ||
import React from 'react'; | ||
import { SkipToContent } from '@patternfly/react-core'; | ||
import { Content, SkipToContent } from '@patternfly/react-core'; | ||
|
||
export const SkipToContentBasic: React.FunctionComponent = () => ( | ||
<React.Fragment> | ||
<SkipToContent href="#main-content">Skip to content</SkipToContent> | ||
<p>Press tab to skip to content at the bottom of the page.</p> | ||
<div style={{ height: '2000px' }}></div> | ||
<h1 id="main-content">Main content</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, nulla | ||
nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat odio, sollicitudin vel | ||
erat vel, interdum mattis neque. Sub works as well! | ||
</p> | ||
<h2>Second level</h2> | ||
<p> | ||
Curabitur accumsan turpis pharetra | ||
<strong>augue tincidunt</strong> blandit. Quisque condimentum maximus mi, sit amet commodo arcu rutrum id. Proin | ||
pretium urna vel cursus venenatis. Suspendisse potenti. Etiam mattis sem rhoncus lacus dapibus facilisis. Donec at | ||
dignissim dui. Ut et neque nisl. | ||
</p> | ||
<ul> | ||
<li>In fermentum leo eu lectus mollis, quis dictum mi aliquet.</li> | ||
<li>Morbi eu nulla lobortis, lobortis est in, fringilla felis.</li> | ||
<li> | ||
Aliquam nec felis in sapien venenatis viverra fermentum nec lectus. | ||
<ul> | ||
<li>In fermentum leo eu lectus mollis, quis dictum mi aliquet.</li> | ||
<li>Morbi eu nulla lobortis, lobortis est in, fringilla felis.</li> | ||
<li> | ||
Ut venenatis, nisl scelerisque. | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li>Integer in volutpat libero.</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Ut non enim metus.</li> | ||
</ul> | ||
<h3>Third level</h3> | ||
<p> | ||
Quisque ante lacus, malesuada ac auctor vitae, congue | ||
<a href="#">non ante</a>. Phasellus lacus ex, semper ac tortor nec, fringilla condimentum orci. Fusce eu rutrum | ||
tellus. | ||
</p> | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li>Integer in volutpat libero.</li> | ||
<li>Donec a diam tellus.</li> | ||
<li> | ||
Etiam auctor nisl et. | ||
<ul> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li> | ||
Integer in volutpat libero. | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Aenean nec tortor orci.</li> | ||
<li>Quisque aliquam cursus urna, non bibendum massa viverra eget.</li> | ||
<li>Vivamus maximus ultricies pulvinar.</li> | ||
</ol> | ||
<blockquote> | ||
Ut venenatis, nisl scelerisque sollicitudin fermentum, quam libero hendrerit ipsum, ut blandit est tellus sit amet | ||
turpis. | ||
</blockquote> | ||
<p> | ||
Quisque at semper enim, eu hendrerit odio. Etiam auctor nisl et | ||
<em>justo sodales</em> elementum. Maecenas ultrices lacus quis neque consectetur, et lobortis nisi molestie. | ||
</p> | ||
<hr /> | ||
<p> | ||
Sed sagittis enim ac tortor maximus rutrum. Nulla facilisi. Donec mattis vulputate risus in luctus. Maecenas | ||
vestibulum interdum commodo. | ||
</p> | ||
<dl> | ||
<dt>Web</dt> | ||
<dd>The part of the internet that contains websites and web pages</dd> | ||
<dt>HTML</dt> | ||
<dd>A markup language for creating web pages</dd> | ||
<dt>CSS</dt> | ||
<dd>A technology to make HTML look better</dd> | ||
</dl> | ||
<p> | ||
Suspendisse egestas sapien non felis placerat elementum. Morbi tortor nisl, suscipit sed mi sit amet, mollis | ||
malesuada nulla. Nulla facilisi. Nullam ac erat ante. | ||
</p> | ||
<h4>Fourth level</h4> | ||
<p> | ||
Nulla efficitur eleifend nisi, sit amet bibendum sapien fringilla ac. Mauris euismod metus a tellus laoreet, at | ||
elementum ex efficitur. | ||
</p> | ||
<p> | ||
Maecenas eleifend sollicitudin dui, faucibus sollicitudin augue cursus non. Ut finibus eleifend arcu ut vehicula. | ||
Mauris eu est maximus est porta condimentum in eu justo. Nulla id iaculis sapien. | ||
</p> | ||
<small>Sometimes you need small text to display things like date created</small> | ||
<p> | ||
Phasellus porttitor enim id metus volutpat ultricies. Ut nisi nunc, blandit sed dapibus at, vestibulum in felis. | ||
Etiam iaculis lorem ac nibh bibendum rhoncus. Nam interdum efficitur ligula sit amet ullamcorper. Etiam tristique, | ||
leo vitae porta faucibus, mi lacus laoreet metus, at cursus leo est vel tellus. Sed ac posuere est. Nunc ultricies | ||
nunc neque, vitae ultricies ex sodales quis. Aliquam eu nibh in libero accumsan pulvinar. Nullam nec nisl | ||
placerat, pretium metus vel, euismod ipsum. Proin tempor cursus nisl vel condimentum. Nam pharetra varius metus | ||
non pellentesque. | ||
</p> | ||
<h5>Fifth level</h5> | ||
<p> | ||
Aliquam sagittis rhoncus vulputate. Cras non luctus sem, sed tincidunt ligula. Vestibulum at nunc elit. Praesent | ||
aliquet ligula mi, in luctus elit volutpat porta. Phasellus molestie diam vel nisi sodales, a eleifend augue | ||
laoreet. Sed nec eleifend justo. Nam et sollicitudin odio. | ||
</p> | ||
<h6>Sixth level</h6> | ||
<p> | ||
Cras in nibh lacinia, venenatis nisi et, auctor urna. Donec pulvinar lacus sed diam dignissim, ut eleifend eros | ||
accumsan. Phasellus non tortor eros. Ut sed rutrum lacus. Etiam purus nunc, scelerisque quis enim vitae, malesuada | ||
ultrices turpis. Nunc vitae maximus purus, nec consectetur dui. Suspendisse euismod, elit vel rutrum commodo, | ||
ipsum tortor maximus dui, sed varius sapien odio vitae est. Etiam at cursus metus. | ||
</p> | ||
</React.Fragment> | ||
); | ||
export const SkipToContentBasic: React.FunctionComponent = () => { | ||
const mainContentId = 'main-content'; | ||
const handleClick = (e) => { | ||
e.preventDefault(); | ||
const mainContentElement = document.getElementById(mainContentId); | ||
if (mainContentElement) { | ||
mainContentElement.focus(); | ||
mainContentElement.scrollIntoView(); | ||
} | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<SkipToContent onClick={handleClick} href={`#${mainContentId}`}> | ||
Skip to content | ||
</SkipToContent> | ||
<p>Press tab to skip to content at the bottom of the page.</p> | ||
<div style={{ height: '2000px' }}></div> | ||
<div tabIndex={-1} id={mainContentId}> | ||
<Content> | ||
<h1>Main content</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, | ||
nulla nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat odio, | ||
sollicitudin vel erat vel, interdum mattis neque. Sub works as well! | ||
</p> | ||
<h2>Second level</h2> | ||
<p> | ||
Curabitur accumsan turpis pharetra | ||
<strong>augue tincidunt</strong> blandit. Quisque condimentum maximus mi, sit amet commodo arcu rutrum id. | ||
Proin pretium urna vel cursus venenatis. Suspendisse potenti. Etiam mattis sem rhoncus lacus dapibus | ||
facilisis. Donec at dignissim dui. Ut et neque nisl. | ||
</p> | ||
<ul> | ||
<li>In fermentum leo eu lectus mollis, quis dictum mi aliquet.</li> | ||
<li>Morbi eu nulla lobortis, lobortis est in, fringilla felis.</li> | ||
<li> | ||
Aliquam nec felis in sapien venenatis viverra fermentum nec lectus. | ||
<ul> | ||
<li>In fermentum leo eu lectus mollis, quis dictum mi aliquet.</li> | ||
<li>Morbi eu nulla lobortis, lobortis est in, fringilla felis.</li> | ||
<li> | ||
Ut venenatis, nisl scelerisque. | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li>Integer in volutpat libero.</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Ut non enim metus.</li> | ||
</ul> | ||
<h3>Third level</h3> | ||
<p> | ||
Quisque ante lacus, malesuada ac auctor vitae, congue | ||
<a href="#">non ante</a>. Phasellus lacus ex, semper ac tortor nec, fringilla condimentum orci. Fusce eu | ||
rutrum tellus. | ||
</p> | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li>Integer in volutpat libero.</li> | ||
<li>Donec a diam tellus.</li> | ||
<li> | ||
Etiam auctor nisl et. | ||
<ul> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
<li> | ||
Integer in volutpat libero. | ||
<ol> | ||
<li>Donec blandit a lorem id convallis.</li> | ||
<li>Cras gravida arcu at diam gravida gravida.</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Aenean nec tortor orci.</li> | ||
<li>Quisque aliquam cursus urna, non bibendum massa viverra eget.</li> | ||
<li>Vivamus maximus ultricies pulvinar.</li> | ||
</ol> | ||
<blockquote> | ||
Ut venenatis, nisl scelerisque sollicitudin fermentum, quam libero hendrerit ipsum, ut blandit est tellus | ||
sit amet turpis. | ||
</blockquote> | ||
<p> | ||
Quisque at semper enim, eu hendrerit odio. Etiam auctor nisl et | ||
<em>justo sodales</em> elementum. Maecenas ultrices lacus quis neque consectetur, et lobortis nisi molestie. | ||
</p> | ||
<hr /> | ||
<p> | ||
Sed sagittis enim ac tortor maximus rutrum. Nulla facilisi. Donec mattis vulputate risus in luctus. Maecenas | ||
vestibulum interdum commodo. | ||
</p> | ||
<dl> | ||
<dt>Web</dt> | ||
<dd>The part of the internet that contains websites and web pages</dd> | ||
<dt>HTML</dt> | ||
<dd>A markup language for creating web pages</dd> | ||
<dt>CSS</dt> | ||
<dd>A technology to make HTML look better</dd> | ||
</dl> | ||
<p> | ||
Suspendisse egestas sapien non felis placerat elementum. Morbi tortor nisl, suscipit sed mi sit amet, mollis | ||
malesuada nulla. Nulla facilisi. Nullam ac erat ante. | ||
</p> | ||
<h4>Fourth level</h4> | ||
<p> | ||
Nulla efficitur eleifend nisi, sit amet bibendum sapien fringilla ac. Mauris euismod metus a tellus laoreet, | ||
at elementum ex efficitur. | ||
</p> | ||
<p> | ||
Maecenas eleifend sollicitudin dui, faucibus sollicitudin augue cursus non. Ut finibus eleifend arcu ut | ||
vehicula. Mauris eu est maximus est porta condimentum in eu justo. Nulla id iaculis sapien. | ||
</p> | ||
<small>Sometimes you need small text to display things like date created</small> | ||
<p> | ||
Phasellus porttitor enim id metus volutpat ultricies. Ut nisi nunc, blandit sed dapibus at, vestibulum in | ||
felis. Etiam iaculis lorem ac nibh bibendum rhoncus. Nam interdum efficitur ligula sit amet ullamcorper. | ||
Etiam tristique, leo vitae porta faucibus, mi lacus laoreet metus, at cursus leo est vel tellus. Sed ac | ||
posuere est. Nunc ultricies nunc neque, vitae ultricies ex sodales quis. Aliquam eu nibh in libero accumsan | ||
pulvinar. Nullam nec nisl placerat, pretium metus vel, euismod ipsum. Proin tempor cursus nisl vel | ||
condimentum. Nam pharetra varius metus non pellentesque. | ||
</p> | ||
<h5>Fifth level</h5> | ||
<p> | ||
Aliquam sagittis rhoncus vulputate. Cras non luctus sem, sed tincidunt ligula. Vestibulum at nunc elit. | ||
Praesent aliquet ligula mi, in luctus elit volutpat porta. Phasellus molestie diam vel nisi sodales, a | ||
eleifend augue laoreet. Sed nec eleifend justo. Nam et sollicitudin odio. | ||
</p> | ||
<h6>Sixth level</h6> | ||
<p> | ||
Cras in nibh lacinia, venenatis nisi et, auctor urna. Donec pulvinar lacus sed diam dignissim, ut eleifend | ||
eros accumsan. Phasellus non tortor eros. Ut sed rutrum lacus. Etiam purus nunc, scelerisque quis enim | ||
vitae, malesuada ultrices turpis. Nunc vitae maximus purus, nec consectetur dui. Suspendisse euismod, elit | ||
vel rutrum commodo, ipsum tortor maximus dui, sed varius sapien odio vitae est. Etiam at cursus metus. | ||
</p> | ||
</Content> | ||
</div> | ||
</React.Fragment> | ||
); | ||
}; |
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
Oops, something went wrong.