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

Post author dropdown: add accessible-autocomplete #7385

Closed
wants to merge 143 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
ea01c26
Merge branch 'master' of github.com:WordPress/gutenberg
Jun 19, 2018
f84c371
accessible autocomplete, first pass
Jun 19, 2018
240c304
Add apiRequest author search
Jun 19, 2018
0d1991d
debounce search, only show autocomplete when more than 50 users
Jun 19, 2018
ea094fb
Add i18n
Jun 19, 2018
642ae6f
cleanup/whitespace
Jun 19, 2018
4ab2777
Only fetch 100 users in getAuthors
Jun 19, 2018
3ebc2c2
Remove the filter that enabled passing `-1` to get the first 10000 us…
Jun 19, 2018
a526c60
remove an old inline comment that is no longer relevant
Jun 19, 2018
a8e9bb1
Add the accessible-autocomplete npm package
Jun 19, 2018
aad6dcb
whitespace
Jun 19, 2018
16dd20c
manually limit search to strings of 2 or more characters
Jun 19, 2018
b056747
use backticks for template literals
Jun 19, 2018
6e69cf0
fixes for eslint
Jun 19, 2018
12e58b0
Revert "Remove the filter that enabled passing `-1` to get the first …
Jun 20, 2018
14edb8a
Merge branch 'master' into feature/accessible-autocomplete
Jul 4, 2018
6d555c7
use <Autocomplete /> component for more than 50 authors
Jul 4, 2018
853dfe6
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 5, 2018
83a7be4
Merge branch 'master' into feature/accessible-autocomplete
Jul 5, 2018
940f338
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 6, 2018
18290b2
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 6, 2018
42c6a60
accessible autocomplete, first pass
Jun 19, 2018
1e322aa
Add apiRequest author search
Jun 19, 2018
8da09fc
debounce search, only show autocomplete when more than 50 users
Jun 19, 2018
e31b540
Add i18n
Jun 19, 2018
7a70911
cleanup/whitespace
Jun 19, 2018
7e7696b
Only fetch 100 users in getAuthors
Jun 19, 2018
6c765c7
Remove the filter that enabled passing `-1` to get the first 10000 us…
Jun 19, 2018
1b10c63
remove an old inline comment that is no longer relevant
Jun 19, 2018
7aab164
Add the accessible-autocomplete npm package
Jun 19, 2018
4e47a3f
whitespace
Jun 19, 2018
03e0155
manually limit search to strings of 2 or more characters
Jun 19, 2018
3e33275
use backticks for template literals
Jun 19, 2018
6238e4c
fixes for eslint
Jun 19, 2018
9d1b490
Revert "Remove the filter that enabled passing `-1` to get the first …
Jun 20, 2018
efac333
use <Autocomplete /> component for more than 50 authors
Jul 4, 2018
7ec4b6c
Bail early if no postAuthor, add missing semicolon
Jul 9, 2018
8a9e711
Hello eslint!
Jul 9, 2018
5173a7a
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Jul 9, 2018
e4915b0
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 9, 2018
86b3d31
Merge branch 'master' into feature/accessible-autocomplete
Jul 9, 2018
d6e1deb
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 27, 2018
6bdba75
Merge branch 'master' into feature/accessible-autocomplete
Jul 27, 2018
a683a1c
update package-lock
Jul 27, 2018
46d27f9
add css
Jul 27, 2018
c3bf43d
Merge remote-tracking branch 'origin/master' into feature/accessible-…
notnownikki Oct 15, 2018
877032a
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Oct 18, 2018
9e42571
Merge branch 'master' of github.com:WordPress/gutenberg
Oct 18, 2018
43ccd6c
Merge branch 'master' into feature/accessible-autocomplete
Oct 18, 2018
79b6c66
include postAuthor data in PostAuthor test
Oct 18, 2018
708fd55
override some dropdown styles
Oct 18, 2018
aa5376f
Merge branch 'master' into feature/accessible-autocomplete
Oct 28, 2018
4f94442
Merge branch 'master' into feature/accessible-autocomplete
Nov 25, 2018
1ecfa05
Merge branch 'master' into feature/accessible-autocomplete
Dec 3, 2018
c6a9b18
update package lock
Dec 3, 2018
06b3cdd
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 10, 2018
319c96c
Merge branch 'master' into feature/accessible-autocomplete
Dec 10, 2018
a97e293
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 14, 2018
839a618
Merge branch 'master' into feature/accessible-autocomplete
Dec 14, 2018
550c63a
current author load on mount
Dec 17, 2018
d1731ec
Set or fetch the current author
Dec 17, 2018
6585f70
If the postAuthor is provided, use it directly. Fixes test, enables p…
Dec 17, 2018
ca3e4be
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 17, 2018
66daf9f
Merge branch 'master' into feature/accessible-autocomplete
Dec 17, 2018
74e4083
Build docs
swissspidy Dec 18, 2018
c70e125
remove unused getAuthor resolver
Dec 18, 2018
cdf7bde
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Dec 18, 2018
4aded2f
lodash!
Dec 18, 2018
f1b5739
findWhere -> find
Dec 18, 2018
d227dfb
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 19, 2018
205f07a
Merge branch 'master' into feature/accessible-autocomplete
Dec 19, 2018
790c2c2
add caching; only debounce remote requests
Dec 19, 2018
cb94e71
Merge branch 'master' of github.com:WordPress/gutenberg
Dec 21, 2018
729037d
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 4, 2019
849949c
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 10, 2019
91a891d
Merge branch 'master' into feature/accessible-autocomplete
Jan 10, 2019
2f1b5e2
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 12, 2019
76090f7
Merge branch 'master' into feature/accessible-autocomplete
Jan 12, 2019
e6a8713
remove autoprefixer
Jan 12, 2019
74e4f71
use string literals
Jan 12, 2019
ac7bedd
use sprintf
Jan 12, 2019
783655c
use _n
Jan 12, 2019
180cd54
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 18, 2019
e45ffe0
Merge branch 'master' into feature/accessible-autocomplete
Jan 18, 2019
525cf40
remove minified styles, unused
Jan 18, 2019
93b5396
imports in order of increasing locality
Jan 18, 2019
9a35172
remove un-needed bind
Jan 18, 2019
31d50b5
re-add disable reason
Jan 18, 2019
50400fc
Style updates
kjellr Jan 24, 2019
ac21e7b
Cleaning up size variables.
kjellr Jan 24, 2019
800787e
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 25, 2019
a021841
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Jan 25, 2019
3fdd917
Merge branch 'master' into feature/accessible-autocomplete
Jan 25, 2019
741a2a8
Remove some unused styles
kjellr Jan 25, 2019
9862909
Merge branch 'master' of github.com:WordPress/gutenberg
Jan 28, 2019
96ed175
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Jan 28, 2019
1980080
Merge branch 'master' into feature/accessible-autocomplete
Jan 28, 2019
624c49d
rearrange constructor calls
Jan 28, 2019
fcaf60d
getInitialPostAuthor to pull author from props
Jan 28, 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
1217076
Merge branch 'master' into feature/accessible-autocomplete
Feb 10, 2019
1d13ad8
improve tStatusResults string construction
Feb 10, 2019
8d3ae5b
remove unused postAuthor check
Feb 10, 2019
db3bea3
adjust z-index use & document
Feb 10, 2019
807b61e
prefix css classes
Feb 10, 2019
5ba93d1
remove autoselect
Feb 10, 2019
0c7d6b5
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 20, 2019
03fc448
Merge branch 'master' of github.com:WordPress/gutenberg
Feb 28, 2019
aa4bbcc
Merge branch 'master' into feature/accessible-autocomplete
Feb 28, 2019
b3839b3
Merge branch 'master' of github.com:WordPress/gutenberg
May 16, 2019
e593595
Merge branch 'master' of github.com:WordPress/gutenberg
Jun 23, 2019
d528303
Merge branch 'master' of github.com:WordPress/gutenberg
Jun 25, 2019
27cedb3
move package.json dependency to editor
Jun 25, 2019
7e5d82d
Merge branch 'master' into feature/accessible-autocomplete
Jun 25, 2019
4c9fd8b
update package lock
Jun 25, 2019
4d8c249
increase author cutoff count to 99 and add inline doc explaining
Jun 25, 2019
b830022
correct translation string
Jun 25, 2019
2426493
ensure unique authors; check found before swetting
Jun 25, 2019
bd6ef21
Improve inline documentation
Jun 26, 2019
0b12bfd
helper for author slugs
Jun 26, 2019
28bf036
display a default list when the current selection is unchanged
Jun 26, 2019
2daaa8c
Post Author: add component tests to document when a select or autocom…
gwwar Jun 27, 2019
1e824ad
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 1, 2019
c89d301
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 2, 2019
8d7db70
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Jul 2, 2019
43d4a59
Merge branch 'master' into feature/accessible-autocomplete
Jul 2, 2019
4c6a447
correct typo
Jul 16, 2019
83f6086
correct typo
Jul 16, 2019
3317851
Merge branch 'feature/accessible-autocomplete' of github.com:WordPres…
Aug 27, 2019
615e3d9
Merge branch 'master' into feature/accessible-autocomplete
Aug 27, 2019
cbea8ff
update packacge-lock
Aug 27, 2019
0066508
merge master
adamsilverstein Dec 20, 2019
ba26d03
Merge branch 'master' into feature/accessible-autocomplete
adamsilverstein Dec 23, 2019
eb64f3b
update package lock
adamsilverstein Dec 23, 2019
24ddea3
Upgrade accessible-autocomplete to version 2.0.1.
adamsilverstein Dec 23, 2019
92e4074
correct doc block typo
adamsilverstein Dec 23, 2019
71b7243
Add post author endpoint to preccache via `block_editor_preload_paths`
adamsilverstein Dec 23, 2019
73343ae
Improve auto-complete styling.
adamsilverstein Dec 23, 2019
e445aa7
Get post author object with a getPostAuthor selector
adamsilverstein Dec 23, 2019
6e129da
Show up to 10 items in menu.
adamsilverstein Dec 23, 2019
e545898
Correct construction of tStatusSelectedOption using sprintf.
adamsilverstein Dec 23, 2019
1c1fb89
Add expected_user_path to tests.
adamsilverstein Dec 23, 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
141 changes: 141 additions & 0 deletions editor/components/post-author/accessible-autocomplete.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
.autocomplete__wrapper {
position: relative;
}

.autocomplete__hint,
.autocomplete__input {
-webkit-appearance: none;
border: 2px solid;
border-radius: 0; /* Safari 10 on iOS adds implicit border rounding. */
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
margin-bottom: 0; /* BUG: Safari 10 on macOS seems to add an implicit margin. */
width: 100%;
}

.autocomplete__input {
background-color: transparent;
position: relative;
}

.autocomplete__hint {
color: #BFC1C3;
position: absolute;
}

.autocomplete__input--default{
padding: 4px;
}

.autocomplete__input--focused {
outline-offset: 0;
outline: 3px solid #ffbf47;
}

.autocomplete__input--show-all-values {
padding: 4px 34px 4px 4px;
cursor: pointer;
}

.autocomplete__dropdown-arrow-down{
z-index: -1;
display: inline-block;
position: absolute;
right: 8px;
width: 24px;
height: 24px;
top: 10px;
}

.autocomplete__menu {
background-color: #fff;
border: 2px solid #0B0C0C;
border-top: 0;
color: #34384B;
margin: 0;
max-height: 342px;
overflow-x: hidden;
padding: 0;
width: 100%;
width: calc(100% - 4px);
}

.autocomplete__menu--visible {
display: block;
}

.autocomplete__menu--hidden {
display: none;
}

.autocomplete__menu--overlay {
box-shadow: rgba(0, 0, 0, 0.256863) 0px 2px 6px;
left: 0;
position: absolute;
top: 100%;
z-index: 100;
}

.autocomplete__menu--inline {
position: relative;
}

.autocomplete__option {
border-bottom: solid #BFC1C3;
border-width: 1px 0;
cursor: pointer;
display: block;
position: relative;
}

.autocomplete__option > * {
pointer-events: none;
}

.autocomplete__option:first-of-type {
border-top-width: 0;
}

.autocomplete__option:last-of-type {
border-bottom-width: 0;
}

.autocomplete__option--odd {
background-color: #FAFAFA;
}

.autocomplete__option--focused,
.autocomplete__option:hover {
background-color: #005EA5;
border-color: #005EA5;
color: white;
outline: none;
}

.autocomplete__option--no-results {
background-color: #FAFAFA;
color: #646b6f;
cursor: not-allowed;
}

.autocomplete__hint,
.autocomplete__input,
.autocomplete__option {
font-size: 16px;
line-height: 1.25;
}

.autocomplete__hint,
.autocomplete__option {
padding: 4px;
}

@media (min-width: 641px) {
.autocomplete__hint,
.autocomplete__input,
.autocomplete__option {
font-size: 19px;
line-height: 1.31579;
}
}
59 changes: 53 additions & 6 deletions editor/components/post-author/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,86 @@ import { __ } from '@wordpress/i18n';
import { withInstanceId } from '@wordpress/components';
import { Component, compose } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import apiRequest from '@wordpress/api-request';

/**
* Internal dependencies
*/
import PostAuthorCheck from './check';

/**
* External dependencies
*/
import accessibleAutocomplete from 'accessible-autocomplete';
import './accessible-autocomplete.css';
import { findWhere, debounce } from 'underscore';

export class PostAuthor extends Component {
constructor() {
super( ...arguments );

this.setAuthorId = this.setAuthorId.bind( this );
this.suggestAuthor = this.suggestAuthor.bind( this );
}

componentDidMount() {
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
const { instanceId, authors } = this.props;
this.authors = authors;
if ( authors.length > 50 ) {
accessibleAutocomplete.enhanceSelectElement( {
selectElement: document.querySelector( '#post-author-selector-' + instanceId ),
minLength: 2,
showAllValues: true,
autoselect: true,
displayMenu: 'overlay',
onConfirm: this.setAuthorId,
source: debounce( this.suggestAuthor, 300 ),
tNoResults: () => __( 'No results found' ),
tStatusQueryTooShort: ( minQueryLength ) => __( `Type in ${ minQueryLength } or more characters for results` ),
tStatusNoResults: () => __( 'No search results' ),
tStatusSelectedOption: ( selectedOption, length ) => __( `${ selectedOption } (1 of ${ length }) is selected` ),
tStatusResults: ( length, contentSelectedOption ) => {
const words = {
result: ( length === 1 ) ? __( 'result' ) : __( 'results' ),
is: ( length === 1 ) ? __( 'is' ) : __( 'are' ),
};
return <span>{ length } { words.result } { words.is } available. { contentSelectedOption }</span>;
},
} );
}
}

suggestAuthor( query, populateResults ) {
if ( query.length < 2 ) {
return;
}
const payload = '?search=' + encodeURIComponent( query );
apiRequest( { path: '/wp/v2/users' + payload } ).done( ( results ) => {
this.authors = results;
populateResults( results.map( ( author ) => ( author.name ) ) );
} );
}

setAuthorId( event ) {
setAuthorId( selectedName ) {
if ( ! selectedName ) {
return;
}
const { onUpdateAuthor } = this.props;
const { value } = event.target;
onUpdateAuthor( Number( value ) );
const author = findWhere( this.authors, { name: selectedName } );
onUpdateAuthor( Number( author.id ) );
}

render() {
const { postAuthor, instanceId, authors } = this.props;
const selectId = 'post-author-selector-' + instanceId;

// Disable reason: A select with an onchange throws a warning

/* eslint-disable jsx-a11y/no-onchange */
return (
<PostAuthorCheck>
<label htmlFor={ selectId }>{ __( 'Author' ) }</label>
<select
id={ selectId }
value={ postAuthor }
onChange={ this.setAuthorId }
className="editor-post-author__select"
>
{ authors.map( ( author ) => (
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@wordpress/custom-templated-path-webpack-plugin": "1.0.2",
"@wordpress/jest-preset-default": "1.0.6",
"@wordpress/scripts": "1.2.0",
"accessible-autocomplete": "1.6.1",
"autoprefixer": "8.2.0",
"babel-core": "6.26.0",
"babel-eslint": "8.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function* getCategories() {
* Requests authors from the REST API.
*/
export async function* getAuthors() {
const users = await apiRequest( { path: '/wp/v2/users/?who=authors&per_page=-1' } );
const users = await apiRequest( { path: '/wp/v2/users/?who=authors&per_page=100' } );
yield receiveUserQuery( 'authors', users );
}

Expand Down