Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expose APIs for clearing focus and selecting item #39

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

Closed
wants to merge 1 commit into from

Conversation

muan
Copy link
Contributor

@muan muan commented Oct 23, 2019

This is dependent on #38, as #38 introduced a new focus state that doesn't go away on its own. I figured this could be worth a separate discussion.

These two functions are useful when there are scripted behaviors that alter menu items. This allows those behaviors to interact with <details-menu> easily, instead of getting into the implementation details of <details-menu>.

For example,

A filtering behavior would want to clear focus after filtering. With this change, it will be able to call detailsMenu.clearFocus() instead of

  1. duplicating details-menu's logic for querying menu items
  2. clearing focus states based on details-menu's implementation

A filtering input would want to trigger an implicit selection for the first filtered result on Enter. With this change, it will be able to invoke detailsMenu.selectFocusOrFirst() instead of

  1. check for currently focused menu item or finding first item by duplicating details-menu's logic for querying menu items
  2. simulate a click() on the item

Example:

menu.addEvenetListener('menuitem-filtered', () => {
  menu.clearFocus()
})
input.addEvenetListener('keypress', event => {
  if (event.key !== 'Enter') return
  input.closest('details-menu').selectFocusOrFirst()
})

Note: In this use case the current focus check in selectFocusOrFirst is redundant, since the input would have focus. "Focus or first" is mostly an explicit name for an implicit default.

These two functions are useful when there are 3rd party script behaviors
that alters menu items. This allows those behaviors to interact with
details-menu without getting into the implementation details of
details-menu.

For example,

- A filtering behavior would want to clear focus after filter. With this
  change, it will be able to call detailsMenu.clearFocus() instead of
  1. duplicating details-menu's logic for querying menu items
  2. clearing focus states based on details-menu's implementation

- A filtering input would want to trigger an implicit selection for the
  the first filtered result. With this change, it will be able to invoke
  detailsMenu.selectFocusOrFirst() instead of
  1. duplicating details-menu's logic for querying menu items
  2. simulate a click() on the item
@@ -31,6 +31,17 @@ class DetailsMenuElement extends HTMLElement {
return input instanceof HTMLInputElement ? input : null
}

clearFocus() {
clearFocus(this)
Copy link
Contributor

Choose a reason for hiding this comment

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

A follow up commit (in this PR or a new one) to inline clearFocus would be good for readability.

@muan
Copy link
Contributor Author

muan commented Feb 5, 2020

We're no longer pursuing this.

@muan muan closed this Feb 5, 2020
@muan muan deleted the filter-input-support branch February 5, 2020 20:00
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