-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
Confirm Modal should submit on Enter
key pressed
#1757
Comments
@ibilux can you link to the source on this please. We follow the ARIA APG guidelines on these sorts of issues to meet a11y concerns: It may be in there, but they cover a lot so just let me know where specifically. |
@ibilux , I found a good discussion here: https://ux.stackexchange.com/questions/130704/enter-key-action-on-modal-dialogs They assert that the enter key should do something, but if "submit" = fire nukes, than the default should probably be "cancel". |
That generally meets my expectations as well, but some of this may be a limitation for our focus trap implementation. What I'm leaning towards is some ways for users to opt into and configuration this behavior in some fashion. Rather than just hardcoded on-by-default. Defaulting to this may not meet everyone's expectations and it may violate some a11y concerns. |
Taking a deeper look at this - one option we have here is the https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus
This doesn't introduce the complexity or lead the possibility of side effects that a form and button type can lead to. However, SvelteKit provides warning against this: In this case I think they are technically correct, this should be used sparingly, but for our use case specifically I think this is the correct option. If so, we'll need to implement this and append a one-off comment to disable this warning like so: <!-- svelte-ignore a11y-autofocus -->
<button type="button" class="btn {buttonPositive}" on:click={onConfirm} autofocus>{buttonTextConfirm}</button> However, we should likely take the UX concerns into play here - that the positive action may not always be the desired focus element. In that case we will need a prop like <button type="button" class="btn {buttonNeutral}" on:click={onClose} autofocus={autofocus === 'neutral'}>
{buttonTextCancel}
</button>
<button type="button" class="btn {buttonPositive}" on:click={onConfirm} autofocus={autofocus === 'positive'}>
{buttonTextConfirm}
</button> I'm not sure I like the complexity of this though, especially given trying to balance the component props settings versus dynamic parameters passed for one-offs. |
@endigo9740 the <script lang="ts">
import { tick } from "svelte";
async function autofocus(node: HTMLElement){
await tick();
node.focus();
}
</script>
<button type="button" class="btn {buttonPositive}" on:click={onConfirm} use:autofocus>
{buttonTextConfirm}
</button>
You are right about the UX. |
I'd certainly ask for a configurable prop, probably in the Interesting questions is if it has 2 or 3 allowed values: The behaviour would be better a11y though, so I think I'd rather have just |
It does work, I tested a working example of it yesterday. SvelteKit can't disable a core browser feature like that. Given the modal component is added and removed from the DOM when a modal is opened or closed, it does work repeatedly. Though you do bring up a good use case for testing multiple confirm prompts back to back. That's an edge case, but one that should be tested
That's where the complexity comes in. I have an idea of how to solve this, but I'll have to investigate. But either way, I don't think the current PR will be our solution. It doesn't account for this and is not nearly as configurable IMO. |
In an effort to prepare for Skeleton v3, we're consolidate some related issues down to a single ticket. This will ensure that we can see the full context of requests when the time comes to refactor and update this feature going forward. If you wish to add additional feedback or suggestions, please so here: |
Confirm Modal should submit true value on
Enter
key pressed (like closing onEscape
key pressed).We should change button type from
type="button"
totype="submit"
.Or use HTML Form Element
<form>
.https://github.com/skeletonlabs/skeleton/blob/fa2af91a23e37a92ddf820c578ffaab135766a99/packages/skeleton/src/lib/utilities/Modal/Modal.svelte#L243C8-L243C8
The text was updated successfully, but these errors were encountered: