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

Document outline: Use links not buttons #10815

Merged
merged 81 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
1ccfe6f
Adjust document outline to use an a tag vs button
Oct 19, 2018
474535f
target href links directly to page anchors, remove onClick handler
Oct 28, 2018
e574784
Merge branch 'master' of github.com:WordPress/gutenberg
Oct 28, 2018
63f4800
Merge branch 'master' into fix/doc-outline
Oct 28, 2018
e62566d
Merge branch 'master' of github.com:WordPress/gutenberg
Oct 30, 2018
ade47e5
Merge branch 'master' into fix/doc-outline
Oct 30, 2018
da9311c
update test snapshot
Oct 30, 2018
8e54535
Merge branch 'master' of github.com:WordPress/gutenberg
Nov 2, 2018
2343fa7
update snapshot
Nov 4, 2018
ef96b90
better titleNode targeting
Nov 4, 2018
3c2a500
update snapshot
Nov 4, 2018
f579dda
update snapshot
Nov 4, 2018
acde4a5
Merge branch 'master' of github.com:WordPress/gutenberg
Nov 7, 2018
20691f3
Merge branch 'master' of github.com:WordPress/gutenberg
Nov 12, 2018
89660bc
Merge branch 'master' of github.com:WordPress/gutenberg
Nov 13, 2018
7aee351
Merge branch 'master' into fix/doc-outline
Nov 18, 2018
e434bae
Close the table of contents panel when a link is clicked
Nov 18, 2018
841bf0f
add deterministic block id to tests
Nov 18, 2018
9082baa
remove redundant screen reader text
Nov 18, 2018
b64b2ed
Adjust map to avoid mutating original object
Nov 20, 2018
e4cc7cf
update snapshot
Nov 20, 2018
55b69f5
Update packages/editor/src/components/document-outline/index.js
tofumatt Nov 20, 2018
46e4e1f
Update packages/editor/src/components/document-outline/test/index.js
tofumatt Nov 20, 2018
0aaaaa0
Update packages/editor/src/components/document-outline/index.js
tofumatt Nov 20, 2018
4f85e47
Merge branch 'master' into fix/doc-outline
Nov 27, 2018
273c7b4
update snapshot
Nov 27, 2018
c69dcf7
Merge branch 'fix/doc-outline' of github.com:WordPress/gutenberg into…
Nov 27, 2018
8b576c2
update snapshots
Nov 27, 2018
275f225
Merge branch 'master' into fix/doc-outline
Dec 1, 2018
eab1548
update snapshot
Dec 3, 2018
6df81db
update snapshots
Dec 4, 2018
4f38edc
fix up e2e tests
Dec 4, 2018
e8aa8d2
Fix snapshots by removing single quotes from outline links
mcsf Dec 9, 2018
33db8e9
Update packages/editor/src/components/document-outline/index.js
mcsf Dec 9, 2018
7d7edf3
Merge branch 'fix/doc-outline' of github.com:WordPress/gutenberg into…
Dec 9, 2018
b85b4c9
change target to href
Dec 9, 2018
f0afad5
rename close -> closeOutline
Dec 10, 2018
06b3cdd
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 10, 2018
a97e293
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 14, 2018
7091d06
Merge branch 'master' into fix/doc-outline
Dec 14, 2018
dd3f8b3
update snapshots after property name changes
Dec 14, 2018
69f94c9
rename close/onClose -> onRequestClose for TOC, on
Dec 16, 2018
7d3f4a9
restore onSelect
Dec 16, 2018
48764d5
complete renaming
Dec 16, 2018
e88aac5
Block links are only valid for the current session - remove hash afte…
Dec 16, 2018
6a6d8d2
update snapshot
Dec 16, 2018
ca3e4be
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 17, 2018
d227dfb
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 19, 2018
cb94e71
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 21, 2018
158bc4a
Merge branch 'master' into fix/doc-outline
Dec 21, 2018
0475978
cleanup; move block id hash removal functionality up to document outl…
Dec 21, 2018
3604126
update snapshot
Dec 21, 2018
729037d
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 4, 2019
7e5be38
Merge branch 'master' into fix/doc-outline
Jan 4, 2019
bada58f
use replaceState vs pushState
Jan 4, 2019
44d6d40
use defer and import at top of file
Jan 4, 2019
d5470e5
removeURLHash as helper
Jan 4, 2019
849949c
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 10, 2019
0a534f6
Merge branch 'master' into fix/doc-outline
Jan 10, 2019
2f1b5e2
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 12, 2019
2a6aacf
Merge branch 'master' into fix/doc-outline
Jan 12, 2019
180cd54
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 18, 2019
7c40fd4
Merge branch 'master' into fix/doc-outline
Jan 18, 2019
cd26b45
Merge branch 'master' into fix/doc-outline
Jan 23, 2019
613bc47
remove passing event in select handler
Jan 23, 2019
99380f2
improve doc block
Jan 23, 2019
800787e
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 25, 2019
506ad72
Merge branch 'master' into fix/doc-outline
Jan 25, 2019
9862909
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 28, 2019
00e3b35
Merge branch 'master' into fix/doc-outline
Jan 28, 2019
ac4d147
Merge branch 'master' into fix/doc-outline
Feb 5, 2019
ca63c58
Skip title in outline when title node not found
Feb 5, 2019
291097c
remove removeURLHash
Feb 5, 2019
da3de52
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 6, 2019
d3443e7
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 10, 2019
0c7d6b5
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 20, 2019
38ca0fe
Merge branch 'master' into fix/doc-outline
Feb 28, 2019
03fc448
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 28, 2019
bdd533f
Merge branch 'master' into fix/doc-outline
Feb 28, 2019
de595d3
Merge branch 'master' of github.com:WordPress/gutenberg
Mar 8, 2019
a04038f
Merge branch 'master' into fix/doc-outline
Mar 8, 2019
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
15 changes: 3 additions & 12 deletions packages/editor/src/components/document-outline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { countBy, flatMap, get } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -61,7 +61,7 @@ const computeOutlineHeadings = ( blocks = [], path = [] ) => {

const isEmptyHeading = ( heading ) => ! heading.attributes.content || heading.attributes.content.length === 0;

export const DocumentOutline = ( { blocks = [], title, onSelect, isTitleSupported } ) => {
export const DocumentOutline = ( { blocks = [], title, isTitleSupported } ) => {
const headings = computeOutlineHeadings( blocks );

if ( headings.length < 1 ) {
Expand All @@ -70,9 +70,6 @@ export const DocumentOutline = ( { blocks = [], title, onSelect, isTitleSupporte

let prevHeadingLevel = 1;

// Select the corresponding block in the main editor
// when clicking on a heading item from the list.
const onSelectHeading = ( clientId ) => onSelect( clientId );
const focusTitle = () => {
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
// Not great but it's the simplest way to focus the title right now.
const titleNode = document.querySelector( '.editor-post-title__input' );
Expand Down Expand Up @@ -115,8 +112,8 @@ export const DocumentOutline = ( { blocks = [], title, onSelect, isTitleSupporte
key={ index }
level={ `H${ item.level }` }
isValid={ isValid }
onClick={ () => onSelectHeading( item.clientId ) }
path={ item.path }
target={ item.clientId }
>
{ item.isEmpty ?
emptyHeadingContent :
Expand Down Expand Up @@ -147,11 +144,5 @@ export default compose(
blocks: getBlocks(),
isTitleSupported: get( postType, [ 'supports', 'title' ], false ),
};
} ),
withDispatch( ( dispatch ) => {
const { selectBlock } = dispatch( 'core/editor' );
return {
onSelect: selectBlock,
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
};
} )
)( DocumentOutline );
8 changes: 4 additions & 4 deletions packages/editor/src/components/document-outline/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const TableOfContentsItem = ( {
children,
isValid,
level,
onClick,
path = [],
target,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this named target instead of just href, seems a bit confusing as target has a different meaning for links?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, good point - i'll change this to href

Copy link
Member Author

Choose a reason for hiding this comment

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

changed in b85b4c9

} ) => (
<li
className={ classnames(
Expand All @@ -29,9 +29,9 @@ const TableOfContentsItem = ( {
}
) }
>
<button
<a
href={ target ? '#block-' + target : '#post-title-1' }
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
className="document-outline__button"
onClick={ onClick }
>
<span className="document-outline__emdash" aria-hidden="true"></span>
{
Expand All @@ -50,7 +50,7 @@ const TableOfContentsItem = ( {
{ children }
</span>
<span className="screen-reader-text">{ __( '(Click to focus this heading)' ) }</span>
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
</button>
</a>
</li>
);

Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/components/document-outline/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
display: flex;
margin: 4px 0;

a {
text-decoration: none;
}

.document-outline__emdash::before {
color: $light-gray-500;
margin-right: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ exports[`DocumentOutline header blocks present should match snapshot 1`] = `
isValid={true}
key="0"
level="H2"
onClick={[Function]}
path={Array []}
target="3fc15d2e-5d52-40b0-9f54-9b9562adeac0"
>
<Component
format="string"
Expand All @@ -22,8 +22,8 @@ exports[`DocumentOutline header blocks present should match snapshot 1`] = `
isValid={true}
key="1"
level="H3"
onClick={[Function]}
path={Array []}
target="6eab6ae4-a33a-4e68-a218-2832860095a2"
>
<Component
format="string"
Expand All @@ -44,8 +44,8 @@ exports[`DocumentOutline header blocks present should render warnings for multip
isValid={false}
key="0"
level="H1"
onClick={[Function]}
path={Array []}
target="34f77241-c57a-4610-a4a7-f0568d999e07"
>
<Component
format="string"
Expand All @@ -65,8 +65,8 @@ exports[`DocumentOutline header blocks present should render warnings for multip
isValid={false}
key="1"
level="H1"
onClick={[Function]}
path={Array []}
target="34f77241-c57a-4610-a4a7-f0568d999e07"
>
<Component
format="string"
Expand Down