Problem/Motivation
Clicking on + to add a taxonomy term field to the index scrolls the page to the top. A user who is not very familiar with Drupal wouldn't know what happened.
Here's how to reproduce the issue:
1) Go to /admin/config/search/search-api/index//fields. Replace in the URL by the machine name of your index.
2) Click on "Add fields" button.
3) You should see a popup similar to the one shown below:

4) Scroll down the page so that you are below the fold.
5) Click on any "(+)" icon. In my case, I clicked on the icon next to "Next steps planned for each goal?" field.
6) JS forces the page to scroll to the top.
Proposed resolution
Page should not scroll to the top.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3022881-8--ajax-add-fields-click-no-scroll.patch | 1.29 KB | drunken monkey |
Issue fork search_api-3022881
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
drunken monkeyThanks for reporting!
You’re right, this is indeed a bit of a UX problem. However, frontend/JS development is unfortunately not my strong suit, so I have to rely on patches from others in this regard. If you, or someone else, would be willing to provide one for this problem, I’d be happy to review and commit.
Comment #3
drunken monkeyAlso, see here: #3006647: Use checkboxes to select fields to add to index.
Comment #4
mahtabalamOn most ajax triggered actions, we are losing the focus on the triggering element as it is removed from the dom then re-added. Please apply the patch to fix that issue.
I have tested on local and work as expected.
Comment #5
mahtabalam@drunken this will also fixed the issue https://www.drupal.org/project/search_api/issues/3006647
Comment #6
mahtabalamComment #7
borisson_Yup, this does seem to help, thanks!
Comment #8
drunken monkeyWow, thank you so much! This has been bugging me for years now, never imagined the solution would be so simple!
However, any reason you didn’t apply the same change to the “Add” button as well? The behavior is the same (and as annoying) there, and the fix seems to work there, too.
Patch attached, please test/review!
Comment #9
borisson_Even better!
Comment #11
drunken monkeyExcellent. I also gave it another test in front of a hundred witnesses, so should be fine.
Committed.
Thanks a lot again!
Comment #12
asterovim commentedThanks a lot ! it's work's.
Comment #15
wotts commentedHey!
This patch is in master, but unfortanetly we still experience this issue.
I tried a few things, but that doesn't work. Here's what I tried:
Cheers!
Comment #16
scott_euser commentedYep as per #15 I could still reproduce it, but I am fixing it in #3484811: Improve the Search API admin UI for adding/editing fields. The problem was drupal ajax attempts to refocus on the expand button, but expand is replaced by the collapse button. We need to maintain a 'data-drupal-selector' element that is consistent between the two so drupal ajax knows its meant to be the same focus target.