-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
WIP Pattern input field #17472
base: dev
Are you sure you want to change the base?
WIP Pattern input field #17472
Conversation
f82ef17
to
896dbd3
Compare
8f324e2
to
428ede5
Compare
02b24d2
to
17ccd5e
Compare
2f587af
to
e20ace7
Compare
e20ace7
to
90e816f
Compare
90e816f
to
e6cd61c
Compare
e6cd61c
to
9f03cd4
Compare
9f03cd4
to
8ca26a9
Compare
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.
I've done some testing mostly from the UI side (i.e. not looking at the code first, but checking behaviour first) and left some comments.
Feel free to give me feedback on whether you agree or disagree to the findings, but also whenever you think that addressing a finding takes too much effort and should rather be extracted to a separate PR.
} | ||
|
||
// move up and down the suggestions selection | ||
if (event.key === 'ArrowUp') { |
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.
What I see is that we implement the behaviour of a select box manually here. This is tricky. For example I noticed that when using a screen reader, the current implementation does not read out my selection when I change it using the arrow keys. A normal select box (e.g. the color selection in the settings tab) does this.
That's an accessibility concern as far as I can tell. However, I realize that the same problem can be observed for two other places in our UI: The project selection in the top left and our emoji autocompleter. So maybe we never solved this so far. (for comparison, the GitHub emoji autocompleter behaves fine)
Sadly I am by no means an expert in implementing accessible custom components. As far as I can tell, the usually best practice is to start with a standard component that is already accessible, e.g. using a real select box in the background.
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.
I am not sure how to handle this, though. I will reach out to other people on the dev team to see if it helps.
But I was more afraid of attempting to change focus/force navigate with something that is supposed to be a shortcut.
Maybe there's an obvious solution.
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.
The idea with using Primer was to fully spport accessibility again, as the Primer components are claimed to be accessible. However, the ActionList in Primer is not meant to be used standalone afaik, so we are more or less misusing it here. Looking at other components where the actionList is used, it is possible to navigate via arrows. Primer has an internal helper called focus-group
for that, see:
- https://github.com/primer/view_components/blob/main/app/components/primer/focus_group.ts
- https://github.com/primer/view_components/blob/main/app/components/primer/alpha/action_menu.html.erb#L2
Maybe, we simply have to add that around our ActionList as well and we can get rid of the custom selection logic. But that is just an educated guess, I don't know what that really works.
This commit introduces a new type of input field which can handle autocomplete with 'tokens', so that we can build patterns like `Example pattern {{token}} value`.
8ca26a9
to
685b5e1
Compare
} | ||
|
||
// close the suggestions | ||
if (event.key === 'Escape' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') { |
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.
(Very optional)
Small suggestion after realizing that using Esc
we can close the auto-completer: What do you think about adding Ctrl+Space
as a combo to open the list again?
After the latest change this can also be useful for cases where the menu accidentially closed during keyboard navigation.
frontend/src/stimulus/controllers/pattern-autocompleter.controller.ts
Outdated
Show resolved
Hide resolved
frontend/src/stimulus/controllers/pattern-autocompleter.controller.ts
Outdated
Show resolved
Hide resolved
Because the PR template always reminds me about it: Should we add our new component also to the Lookbook? I am not quite sure how this works, but I guess we need to add a file like |
|
||
def select_item_action | ||
{ | ||
action: "click->pattern-autocompleter#suggestions_select", |
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.
I just spotted this one and noticed that I didn't try using the mouse to select an autocomplete entry yet.
For me it doesn't work to click on an autoselect entry. The pop-up closes, but nothing gets selected.
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.
New learning: Selecting with the mouse works after opening the suggestion list via the arrow down button, but not when using the mouse after starting autocompletion via typing.
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.
I shall investigate. Maybe the focus group solution suggested above fixes all things and I can move on with life 👀
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.
Hi @brunopagno
I don't know which detail of review you want at that point. I will just write down the issues I found, feel free to ignore when you already aware of that.
- When loading the page, the field is shortly shown. Sometimes, it there so long that I even could start typing before it vanished
-
The search results are only selectable via keyboard, not via mouse click
-
The label text and closing "x" are not alligned
- The labels can overflow the input
- When there are no search results, the headlines are still shown, which feels weird
- I can't reliably reproduce it, but sometimes there are issues with the cursor position which is jumping around. For example when you select a label as the first element, it jumps to the right after pressing space.
In general it works nicely. Looking at the code, it still feels however as if we should have solved that differently from the UX side from the beginning. We are implementing a lot of custom stuff here and misusing components for that. I know that it is too late now, but we should keep that in mind for later similar cases.
) | ||
) do | ||
%> | ||
<%= content_tag(:span, style: "cursor: default;", "data-role": "token-text") { "__VALUE__" } %> |
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.
Please do not use inline styles. Either use system_arguments or if the style is not supported, add a class and write the styles in the CSS file.
<%= | ||
render( | ||
Primer::Beta::Octicon.new( | ||
icon: :x, size: :xsmall, style: "cursor: pointer;margin: 0.2em;", |
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.
<% end %> | ||
</template> | ||
|
||
<%= content_tag(:div, style: "position: relative;") do %> |
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.
<%= content_tag(:div, style: "position: relative;") do %> | |
<%= render(Primer::BaseComponent.new(tag: :div, position: :relative)) do %> |
Primer::Beta::Octicon.new( | ||
icon: "triangle-down", | ||
size: :small, | ||
style: "cursor: pointer;position: absolute;right: 1em;top: 0.5em;", |
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.
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.
I didn't see that arrow down at all until now 🙈
Devils advocate: Do we need this arrow at all? It makes the component look like a select, when it is mostly like a text input. E.g. we'd also not show an arrow down in a text input that allows autocompleting emojis (which I think is a good analogy for what we are doing here).
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.
The arrow allows for a mouse only interaction of adding tokens so I think it might be necessary. 🤔
@@ -0,0 +1,5 @@ | |||
.pattern-autocompleter | |||
.selected | |||
color: var(--list-item-hover--color) |
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.
Looking at the ActionList component, they use --fgColor-default
for hovered elements. As we try to mimic that style, I'd suggest that we use the same here.
} | ||
|
||
// move up and down the suggestions selection | ||
if (event.key === 'ArrowUp') { |
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.
The idea with using Primer was to fully spport accessibility again, as the Primer components are claimed to be accessible. However, the ActionList in Primer is not meant to be used standalone afaik, so we are more or less misusing it here. Looking at other components where the actionList is used, it is possible to navigate via arrows. Primer has an internal helper called focus-group
for that, see:
- https://github.com/primer/view_components/blob/main/app/components/primer/focus_group.ts
- https://github.com/primer/view_components/blob/main/app/components/primer/alpha/action_menu.html.erb#L2
Maybe, we simply have to add that around our ActionList as well and we can get rid of the custom selection logic. But that is just an educated guess, I don't know what that really works.
Ticket
https://community.openproject.org/projects/document-workflows-stream/work_packages/59999
What are you trying to accomplish?
Fancy input
Screenshots
Screencast.From.2025-01-14.10-36-22.mp4
What approach did you choose and why?
The component was built with rails leveraging stimulus + primer where available. There is minimal custom styling. That said, the component does not look like Figma because we wanted to favour primer components.
A few decisions were made here: