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

Prevent autocompleter from letting users insert two More blocks #7166

Merged
merged 1 commit into from
Jun 7, 2018

Conversation

noisysocks
Copy link
Member

@noisysocks 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—ha ha, you can't! 😏

Make autocompleters respect the isDisabled property that's set by getInserterItems().
@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels Jun 6, 2018
@noisysocks noisysocks requested a review from brandonpayton June 6, 2018 07:20
@@ -242,6 +250,10 @@ export class Autocomplete extends Component {
const { open, range, query } = this.state;
const { getOptionCompletion } = open || {};

if ( option.isDisabled ) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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 );
Copy link
Member

@brandonpayton brandonpayton Jun 7, 2018

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

@brandonpayton brandonpayton left a comment

Choose a reason for hiding this comment

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

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
@noisysocks noisysocks deleted the fix/autocompleter-more-button branch June 7, 2018 04:48
@noisysocks
Copy link
Member Author

Thanks Brandon! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocompleter lets you insert multiple More blocks
3 participants