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

See if using ShadowRoot.delegatesFocus allows us to call .focus on any focusable calcite component #3626

Closed
eriklharper opened this issue Dec 3, 2021 · 2 comments
Assignees
Labels
1 - assigned Issues that are assigned to a sprint and a team member. research Issues that require more in-depth research or multiple team members to resolve or make decision.

Comments

@eriklharper
Copy link
Contributor

eriklharper commented Dec 3, 2021

Background

Focusable calcite components have been implementing a setFocus method as a recommended convention from Ionic, but the HTMLElement.focus() method would be nicer to be able to use since it is common to all HTMLElements. This issue will explore whether using ShadowRoot.delegatesFocus will allow any focusable calcite component to be able to rely on the built-in focus method.

If this works, even though this feature isn't fully supported in all the browser versions Calcite officially supports, it is likely we'll be able to implement this in addition to keeping the setFocus implementation around, at least until it is no longer needed.

https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus

Desired Outcome

Build a prototype example showcasing the ability to call focus() on a focusable calcite component using ShadowRoot.delegatesFocus.

Additional Resources

@eriklharper eriklharper added research Issues that require more in-depth research or multiple team members to resolve or make decision. 0 - new New issues that need assignment. needs triage Planning workflow - pending design/dev review. labels Dec 3, 2021
@jcfranco jcfranco added this to the Freezer milestone Dec 3, 2021
@jcfranco jcfranco removed the needs triage Planning workflow - pending design/dev review. label Dec 3, 2021
@benelan benelan self-assigned this Dec 30, 2022
@benelan benelan added 1 - assigned Issues that are assigned to a sprint and a team member. and removed 0 - new New issues that need assignment. labels Dec 30, 2022
@benelan
Copy link
Member

benelan commented Dec 30, 2022

You can use focus() on component's with delegatesFocus enabled like this:

(async () => {
  await customElements.whenDefined("calcite-date-picker");
  const el = await document
    .querySelector("calcite-date-picker")
    .componentOnReady();
  requestAnimationFrame(() => el.focus());
})();

However, after #6156 it will be simplified to this when using setFocus:

 customElements
    .whenDefined("calcite-date-picker")
    .then(() => document.querySelector("calcite-date-picker").setFocus());

Not all of the components have delegatesFocus enabled right now, see #5147 (comment) for more info. But in terms of the research for this issue I think that's done and confirmed that it will work. Should we close this? @driskull @eriklharper @geospatialem

@driskull
Copy link
Member

Yeah lets close this 👍

I still think we will keep our setFocus methods in the near future because inside of our setFocus methods we can:

  • Wait for componentOnReady() since our setFocus methods are async and return promises
  • Wait for requestAnimationFrame()

I think those are the only two benefits of having our own focus methods. Otherwise, as noted by @benelan, the user has to wait for componentOnReady and requestAnimationFrame()

@benelan benelan closed this as completed Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - assigned Issues that are assigned to a sprint and a team member. research Issues that require more in-depth research or multiple team members to resolve or make decision.
Projects
None yet
Development

No branches or pull requests

5 participants