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

Implement Search as ARIA spec compliant* dialog and combobox pattern #2831

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

phoneticallySAARTHaK
Copy link

@phoneticallySAARTHaK phoneticallySAARTHaK commented Jan 20, 2025

Pretty much a complete rewrite of the UI and UI logic for search.

UI Changes:

  • fix height calculations in sectioning containers to remove extra scrollbars/overflows
  • Fixes tab order of toolbar links
  • Replaces search input with a button in toolbar, which in turn open a dialog, that has the search, which can be opened by clicking the button or pressing "/", or Ctrl+K
  • Implement search as combobox pattern (and all the changes that comes along with it)
  • Enabled virtualKeyboard API to adjust dialog height when keyboard opens in mobile (currently only chromium browsers support it)
  • Removes the ready class from search element.
  • Updat color variable to satisfy WCAG level AA

More details are in commit messages. I haven't updated the changelog, because I don't know what's relevant.

Visual Regression script probably won't detect the change?

*Mostly. There might be minor variations

- Add top margin to `.tsd-breadcrumb` in mobile screen
- Remove top margin from `.tsd-navigation.settings`
- Remove top padding from `.col-sidebar` on single sidebar
- Remove margin for `.site-menu` on larger screens
- Move selectors (`#tsd-toolbar-links`, tag selectors) to a relevant place.
- Remove classes (`.table-cell`, `.no-caption`, `.tsd-toolbar-icon`), and merge their styles to other common classes.
…cript

- **theme_search_index_not_available**
- **theme_search_no_results**
- theme_search_placeholder
- **theme_search_no_recent_searches**
- Use HTML dialog element as popup
- Use ARIA-spec compliant "combobox with list autocomplete" pattern for search
- Add entry animations
- Comment out affected dead code for keyboard event listeners
- store recent searches (that were clicked) in localStorage, with `tsd-search-recent` key
- Omit `matchData` property in `res`'s type to make it compatible with recent searches stored in localStorage.
- This implementation prevents broken links, but refs might change, changing the suggestions
@Gerrit0 Gerrit0 mentioned this pull request Jan 25, 2025
15 tasks
static/style.css Outdated Show resolved Hide resolved
Copy link
Collaborator

@Gerrit0 Gerrit0 left a comment

Choose a reason for hiding this comment

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

A couple general issues:

  1. With no search history, typing something and then clearing the search field results in the claim "No Recent Searches"... which is rather confusing, I just searched for something! Didn't click on anything, but... maybe that's expected, but it greatly confused me for a bit.
  2. This introduced some contrast issues in the new search dialog (run chromium's lighthouse checks)

This is looking really awesome! It seems to behave significantly better on mobile and I like the change on desktop as well

@Gerrit0 Gerrit0 added this to the v0.28.0 milestone Jan 25, 2025
@phoneticallySAARTHaK
Copy link
Author

Regarding the recent searches message, yup, totally agree, I think even left a comment about in the code that it's actually search results. I picked up it up from remix.run, and I'm confused what to show there, "no recent... What?"

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 25, 2025

Would it be better to just not show anything there? It's a different dialog size, but just showing a search bar the first time it is opened doesn't seem completely wrong to me.

I also just realized that storing IDs is not necessarily the way we should go about that. IDs are somewhat likely to change between rebuilds of the site as they are dependent on conversion order, so if the very first class TypeDoc converts gets a new property, all the IDs will end up shifted.

@phoneticallySAARTHaK
Copy link
Author

phoneticallySAARTHaK commented Jan 25, 2025

Edit: Removing it.

... Yup, I mainly added for cosmetic UX purposes. It's not important and I already had doubts about it (that's why it's the last commit).

Without anything it feels.. empty. I'll get some quick design advice on this, otherwise I'll just remove it.

And yes I tested the change of IDs, I still added it on the premises that atleast it won't crash.

From commit message:

  • This implementation prevents broken links, but refs might change, changing the suggestions

It was the simplest way to achieve it, and I don't wanna make it complicated, so I'll probably just remove it. But I don't think occasional changing suggestions is a big deal. But after all, it is a bug.

So here's my confusion:

  • last search is mainly for UX, to not have a tiny search dialog
  • The message "no recent search" is a bit confusing, it should probably be changed.
  • it could be a useful feature, but current implementation has a minor bug.
  • That shouldn't be a big issue, and a lot of people probably wouldn't even notice.

Tradeoffs everywhere.. What are your thoughts about it?

This reverts commit 1beacfa,
and the new i18n strings added in 3548d14.
- fix typo (requierd -> required)
- Remove unnecessary try-catch
- Add falsy check for document.getElementById argument to avoid console warning in firefox
All children of a listbox must be options, showing error message in an li tag without role=option was invalid. An alternative approach is to use another element with aria-live=polite attribute, to announce the results to the user.

However, consecutive queries with no results wouldn't be announced (because the message would be the same), so add search query as part of the message to make it dynamic

- Add a new element with aria-live and aria-atomic attributes for a helpful message
- Remove unnecessary attribute selector for search results.
- Add styles height/margin styles for non-empty elements only.
- Add maxLength to input
}

const item = document.createElement("li");
item.id = `tsd-search:${optionsIdCounter}-${i}`;
item.role = "option";
item.ariaSelected = "false";
item.classList.value = row.classes ?? "";

Choose a reason for hiding this comment

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

Figure out how to override filter styles to not affect search results

- Add background-active and contrast-text css properties
- update text-aside, menu-item-active color in light theme
- break light and dark colors in separate selectors to make them easier to work with

"contrast-text" slightly improves contrast. though, not enough to pass WCAG level AAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants