-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Blocks: Add blocks "slash" autocomplete on default block #2630
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2630 +/- ##
==========================================
+ Coverage 31.31% 32.23% +0.92%
==========================================
Files 178 181 +3
Lines 5429 5525 +96
Branches 949 968 +19
==========================================
+ Hits 1700 1781 +81
- Misses 3154 3166 +12
- Partials 575 578 +3
Continue to review full report at Codecov.
|
From a user point of view, I really like the idea. I think it could be a great way to add blocks. 👍 |
Ideally, I think this should show the new block as selected after making a replacement. In fact, it is selected, but the |
I think this is fine, it respects the flow of writing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good job, works great.
I also see a lot of refactor opportunities:
-
I think we can use the
Popover
component and avoid following the cursor position (That's how slack work) -
the
dropdown
component should probably be splitted, and reused accross different places (FormtTokenField, Autocomplete, Table Block, Switcher)
components/autocomplete/index.js
Outdated
onBlur={ this.onBlur } | ||
className={ classes } | ||
> | ||
{ cloneElement( Children.only( children ), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, the input (or conteneditable) should have the following aria attributes:
role="combobox"
aria-expanded={ isExpanded }
aria-autocomplete="list"
aria-owns={ suggestionsListID }
aria-activedescendant={ selectedSuggestionListItemId }
the list should have
role="listbox"
and each list item should have
role="option"
aria-selected={ index === this.props.selectedIndex }
Could mimic the FormTokenField
component
Made some updates to reuse the I'm postponing the accessibility changes, because this component is a bit "special". my question here is: Should we add all these combobox attributes knowing that this component won't behave as an autocomplete component if we do not type "/". It's just the paragraph block. I was thinking adding these attributes could be confusing. @afercia Anyway, I think we can merge this and address the remaining reusability and accessibility issues separately. |
First, really enjoying using this! Great work everyone on this. I did find one thing that maybe is more of a 'tweak' than a bug. If you do the following:
I can see a possible user flow of changing blocks through the slash command. Is this expected or a bug? |
@karmatosed this is expected as, this is only implemented for the paragraph block (the default block). Extending to other blocks is possible (opt-in). |
Ah crumbs, totally missed it was just for default block! That totally explains it. Whilst this works for a v1, I think that adding into all blocks pretty soon after is important. I won't be only one getting hit by an expectation failure. |
Surprisingly this worked previously even when label was an array, since RegExp#test will coerce its argument to a string, but it would also produce false positives on an e.g. "object" search, since the coerced value would appear as "[object Object],example" (result of: String( [ {}, 'example' ] ) )
Supporting non-empty will require more work, specifically around detecting the offset of the selection to determine where the input exists, and the search term to match
3b5cfa8
to
c88352a
Compare
Just tested and well, I guess you know the answer 🙂 |
Related: #834
Supersedes: #2284
This pull request seeks to enable a user to add a block by typing a slash
/
in a new default paragraph block, followed by a search parameter. Using arrow keys and click/enter on a block result will replace the paragraph block with a new block of the selected type.Implementation notes:
There's a bit of reinventing the wheel here, but unfortunately I wasn't able to reuse very much:
contenteditable
, onlyinput
contenteditable
, and Caret.js is dependent on jQueryThere may still be opportunity for refactoring to consolidate some of these behaviors.
Testing instructions:
Verify that you can insert a new block from an empty paragraph block by typing slash, followed by a block search.
/