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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent autocompleter from letting users insert two More blocks #7166

Merged
merged 1 commit into from Jun 7, 2018

Conversation

Projects
None yet
3 participants
@noisysocks
Member

noisysocks commented Jun 6, 2018

Fixes #4225.

Makes autocompleters respect the isDisabled property that's set by getInserterItems(). This means that one can no longer insert two More blocks via the / autocompleter.

more-fix

How has this been tested?

  1. Create a new post
  2. Insert a More block using the / shortcut.
  3. Insert another More block using the / shortcut鈥攈a ha, you can't! 馃槒
Prevent autocompleter from letting one insert two More blocks
Make autocompleters respect the isDisabled property that's set by getInserterItems().
@@ -242,6 +250,10 @@ export class Autocomplete extends Component {
const { open, range, query } = this.state;
const { getOptionCompletion } = open || {};
if ( option.isDisabled ) {

This comment has been minimized.

@brandonpayton

brandonpayton Jun 7, 2018

Member

I wondered why this was necessary due to the button actually being disabled. Now I see it is due to the fact that our keyboard listener calls select with indiscriminately when ENTER is pressed. I wonder if it would be clearer to conditionally call select in handleKeyDown. Just sharing my experience in case you concur.

This comment has been minimized.

@noisysocks

noisysocks Jun 7, 2018

Member

Yeah, we re-use select() in both the keyDown and onClick handlers. I think it's OK to leave as is.

@@ -345,6 +357,7 @@ export class Autocomplete extends Component {
value: optionData,
label: completer.getOptionLabel( optionData ),
keywords: completer.getOptionKeywords ? completer.getOptionKeywords( optionData ) : [],
isDisabled: completer.isOptionDisabled ? completer.isOptionDisabled( optionData ) : false,
} ) );
const filteredOptions = filterOptions( this.state.search, keyedOptions );

This comment has been minimized.

@brandonpayton

brandonpayton Jun 7, 2018

Member

It may be a pathological case, but since we show a limited number of options at a time, it is technically possible for all shown options to be disabled. Maybe we should update filterOptions to sort disabled options to the end before filtering.

This comment has been minimized.

@noisysocks

noisysocks Jun 7, 2018

Member

Really like this idea, but let's punt on it until disabled items are a more common occurrence. Right now it's really only the More block case that we have to support.

@brandonpayton

Thanks for fixing this!

I left a couple of comments, but I don't think either should be blockers for getting this in.

@noisysocks noisysocks merged commit 102445b into master Jun 7, 2018

2 checks passed

codecov/project 46.5% (+0.01%) compared to f6587ce
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@noisysocks noisysocks deleted the fix/autocompleter-more-button branch Jun 7, 2018

@noisysocks

This comment has been minimized.

Member

noisysocks commented Jun 7, 2018

Thanks Brandon! 鉂わ笍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment