-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
Feat/focus trap specified #2191
Conversation
🦋 Changeset detectedLatest commit: 0fb8dc4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks @doic everyone looks good with a quick scan. I tend to do proper PR reviews on Fridays, so expect at least at least some preliminary feedback tomorrow. When you're ready for a proper review, tap the "ready for review" option here. Thanks! UPDATE Per the CI deployment, it looks like svelte-check is failing. If you could please review that with |
Done. I had run pnpm check before messing with the Modal, sorry :-( |
@doic so a few issues here -
Per Issue 1, by making the value of Per issues 2 and 3 above, this can be tested by inserted focusable elements with
Please @ me here when you've corrected these issues and are ready for a follow up review please! |
Weird. Check command worked on my machine. I'll check everything tomorrow morning. Thanks for the feedback 👍 |
OK - I had run someBool ? tabIndex : tabIndex + 1 Obviously, this makes |
By the way, the more I see |
Hey @doic I handle PR reviews on Sundays now. Just gave this a quick scan. I see you received some feedback from Mahmoud, but I don't see any commits beyond that. I'll try to squeeze in another review on Tuesday (our next release) otherwise expect a follow up later in the week. |
Yes sorry, I've been quite busy these days. I'll try to get back to it during the week. |
I'm back 😁 |
The easiest way - imo - to do this would be with css selectors (allowing to use id attributes if we prefer): <form use:focusTrap={{ enabled: true, initialFocus: 'input[type=email]' }}>
<input type="text" placeholder="Name" />
<input type="email" placeholder="Email" />
<button class="btn variant-filled-primary">Submit</button>
</form> |
@doic I'll plan to do PR reviews tomorrow. I'll dive into this then. |
@doic a lot of the original ideas were based on a tabindex-like system, something that would handle fallbacks and conditional statements where the focusable element might change as state updates. Imagine you had a conditional statement inside a Drawer or Modal content like this: <div>
{#if someBool}
<button data-tabindex="0">Button 1</button >
{#else}
<button data-tabindex="1">Button 2</button >
{/if}
<button data-tabindex="2">Button 3</button >
</div> Based on the state of However, I do agree the naming is not quite semantic. We're appending attributes purely meant to be used by the focus trap. As such, I'd recommend we do strive to maintain the same goals for functionality, but provide more semantic naming. I tend to favor shorter, single word values whenever possible. Then let JSDocs provide more context via Intellesense. So I'd recommend something like:
Let me know if that makes sense. |
@endigo9740, in your example, we'll have either 0 or 1 as the smallest available We currently have something that behaves like this: But I sense (in your example) that the If I'm correct, then this feels very tabindex-like and easier to use. We just need to use It will be more consistent with the previous |
Yeah sorry, two different thoughts there that bled together. Yeah if we have the index model we go for the smallest index and a specified value is not required.
Yep, exactly this. |
@Mahmoud-zino don't hesitate to give feedback on this last commit, the previous ones were very useful 🙏 |
@doic the code looks good to me, I would just suggest changing the description in the docs to something like this: Focus orderSpecify the order of focusable elements by assigning a value to the |
@Mahmoud-zino done 🙏 |
@doic I know this issue is waiting on me, but my schedule has blown up lately. I have some free time coming up in a couple weeks, so worst case I'll jump on this again then. Thanks so much for your patience, I'm very excited to get this implemented when possible! |
@endigo9740 sure, no problem :-) I hope this will make it to one of the next releases ! |
@doic I'm actually doing PR reviews as we speak today! So far we're down from 14 -> 5. So I'm slowly inching my way in this direction :) |
@doic with the smaller PRs sorted today I'm going to aim to jump on yours and the few other remaining tomorrow post-release. Your PR is a bit more broad in scope so I want to make sure I devote enough time to testing, rather than to rush it in last minute. Expect some updates on this tomorrow. If things are close enough I may go ahead and make a few modifications myself directly to help wrap this up. I'll let you know! |
@doic @Mahmoud-zino I've pushed some very minor changes to the documentation info and examples. If you two sign off on this I'm happy to merge. The feature is working exactly as expected. Great job! |
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 description looks better, indeed, but I don't understand why hardcoding use:focusTrap={true}
line 104 ?
I basically copied the example above - where use:focusTrap={isFocused}
(line 54)
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.
In the first example we're teaching folks how to toggle the focus trap on and off. No need to repeat that here. The area of focus is focusindex
values.
We strive to keep our examples as minimal as possible, given the small team. It keeps things simpler to maintain over time the less repetition we have.
Linked Issue
Closes #2190
Description
The goal is to allow focusTrap to focus on a specified element. If no element is specified, focusTrap will focus on the first focusable element, taking into consideration the tabindex attributes:
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
Focus specified elements are targeted thanks to their data-tabindex attribute, which don't conflict with the tabindex attribute.
Changsets
Instructions: Changesets automate our changelog. If you modify files in
/packages/skeleton
, runpnpm changeset
in the root of the monorepo, follow the prompts, then commit the markdown file. Changes that add features should beminor
while chores and bugfixes should bepatch
. Please prefix the changeset message withfeat:
,bugfix:
orchore:
.Checklist
Please read and apply all contribution requirements.
dev
branch (NEVERmaster
)docs/
,feat/
,chore/
,bugfix/
pnpm check
pnpm format
pnpm test