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

update/3329: Changed autocomplete menu "ul > li > button" to "div > button" #3343

Merged
merged 15 commits into from
Nov 13, 2017
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
829dfea
update/3329: Changed autocomplete menu "ul > li > button" to "div > b…
tiny-james Nov 6, 2017
3c6b8f9
update/3329: Updated selector to be more specific to fix tests
tiny-james Nov 6, 2017
570fbee
update/3329: Fix styling - images don't shrink, text has max-width
tiny-james Nov 7, 2017
73a6231
Merge branch 'master' into update/3329-autocomplete-aria-markup-impro…
tiny-james Nov 7, 2017
c229639
update/3329: specify profile picture size to avoid resizing after load
tiny-james Nov 7, 2017
fa85051
update/3329: ESC suppresses popup, CTRL+SPACE reshows; List count spo…
tiny-james Nov 7, 2017
7d8aedb
Merge branch 'master' into update/3329-autocomplete-aria-markup-impro…
tiny-james Nov 7, 2017
49413dc
Merge branch 'master' into update/3329-autocomplete-aria-markup-impro…
tiny-james Nov 9, 2017
334ed13
update/3329: Autocompleter matches after word boundaries or space
tiny-james Nov 9, 2017
5c2570c
Merge branch 'master' into update/3329-autocomplete-aria-markup-impro…
tiny-james Nov 10, 2017
45c3a55
update/3329: Fix the list staying suppressed when the cursor is moved
tiny-james Nov 10, 2017
0d0e8f2
Merge branch 'master' into update/3329-autocomplete-aria-markup-impro…
tiny-james Nov 13, 2017
b3325c1
update/3329: fixed withFocusOutside position in call order
tiny-james Nov 13, 2017
5976604
update/3329: Renamed classes to follow BEM style guide
tiny-james Nov 13, 2017
bdeff5a
update/3329: Bracketed test of turnary statement to improve readability
tiny-james Nov 13, 2017
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
Prev Previous commit
Next Next commit
update/3329: Fix the list staying suppressed when the cursor is moved
  • Loading branch information
tiny-james committed Nov 10, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 45c3a555186978880399334a4936092bed801ec3
49 changes: 37 additions & 12 deletions components/autocomplete/index.js
Original file line number Diff line number Diff line change
@@ -127,8 +127,9 @@ export class Autocomplete extends Component {
this.bindNode = this.bindNode.bind( this );
this.select = this.select.bind( this );
this.reset = this.reset.bind( this );
this.resetWhenSuppressed = this.resetWhenSuppressed.bind( this );
this.search = this.search.bind( this );
this.setSelectedIndex = this.setSelectedIndex.bind( this );
this.handleKeyDown = this.handleKeyDown.bind( this );
this.getWordRect = this.getWordRect.bind( this );

this.state = this.constructor.getInitialState();
@@ -168,6 +169,13 @@ export class Autocomplete extends Component {
this.setState( this.constructor.getInitialState() );
}

resetWhenSuppressed() {
const { open, suppress } = this.state;
if ( open && suppress === open.idx ) {
this.reset();
}
}

handleFocusOutside() {
this.reset();
}
@@ -332,21 +340,35 @@ export class Autocomplete extends Component {
}
}

setSelectedIndex( event ) {
handleKeyDown( event ) {
const { open, suppress, selectedIndex, filteredOptions } = this.state;
if ( ! open || filteredOptions.length === 0 ) {
if ( ! open ) {
return;
}
if ( suppress === open.idx ) {
const { keyCode, ctrlKey, shiftKey, altKey, metaKey } = event;
if ( keyCode === SPACE && ctrlKey && ! ( shiftKey || altKey || metaKey ) ) {
this.setState( { suppress: undefined } );
event.preventDefault();
event.stopPropagation();
switch ( event.keyCode ) {
// cancel popup suppression on CTRL+SPACE
case SPACE:
const { ctrlKey, shiftKey, altKey, metaKey } = event;
if ( ctrlKey && ! ( shiftKey || altKey || metaKey ) ) {
this.setState( { suppress: undefined } );
event.preventDefault();
event.stopPropagation();
}
break;

// reset on cursor movement
case UP:
case DOWN:
case LEFT:
case RIGHT:
this.reset();
}
return;
}

if ( filteredOptions.length === 0 ) {
return;
}
let nextSelectedIndex;
switch ( event.keyCode ) {
case UP:
@@ -404,7 +426,7 @@ export class Autocomplete extends Component {
// and avoid Editable getting the event from TinyMCE, hence we must
// register a native event handler.
const handler = isListening ? 'addEventListener' : 'removeEventListener';
this.node[ handler ]( 'keydown', this.setSelectedIndex, true );
this.node[ handler ]( 'keydown', this.handleKeyDown, true );
}

componentDidUpdate( prevProps, prevState ) {
@@ -428,11 +450,13 @@ export class Autocomplete extends Component {
const isExpanded = suppress !== idx && filteredOptions.length > 0;
const listBoxId = isExpanded ? `components-autocomplete-listbox-${ instanceId }` : null;
const activeId = isExpanded ? `components-autocomplete-item-${ instanceId }-${ selectedKey }` : null;

// Disable reason: Clicking the editor should reset the autocomplete when the menu is suppressed
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
return (
<div
ref={ this.bindNode }
onInput={ this.search }
onClick={ this.resetWhenSuppressed }
className="components-autocomplete"
>
{ children( { isExpanded, listBoxId, activeId } ) }
@@ -467,11 +491,12 @@ export class Autocomplete extends Component {
</Popover>
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
}
}

export default flowRight( [
withInstanceId,
withFocusOutside,
withSpokenMessages,
withSpokenMessages,
] )( Autocomplete );