-
Notifications
You must be signed in to change notification settings - Fork 58
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
Invokers API #920
Comments
@plinss and I discussed this briefly and while we think the overall capability looks good, we have some questions: Is there a way to detect that this feature exists? Why is there no generic Why does Why does the Is there a polyfill planned? Does invoking alter focus? If something is invoked, does that receive focus? It seems like this would usually be the case, but some actions might not need that. Pausing a video doesn't need to draw focus, but you would want to focus |
Checking if an element has an
While this is possible it would be potentially superfluous, popovers already have a togglePopover() function for example. It has been considered that actions should have a corresponding JS API though but idk if it makes sense to have the two go hand in hand always.
Auto is the missing value default for the invokeaction attribute. `toggle' is just an explicit token for said action in the details case. This is something we're not entirely sure on and intentionally it's left as a question for future as it's not a blocker for v1 actions.
Apologies this is a mistake in the explainer.
|
I Think this ultimately depends on the action itself like you say for showPicker the select should be focused, for pause a video probably not. We'll ensure these are concretely specced. |
To further help in your review of the explainer (though your feedback and input on the extended feature design is definitely welcome and encouraged) it may be worth noting that the initial version only has actions for popover and Modal Dialogs. Along with the concept of custom actions and their associated naming restrictions. |
To add to Luke's commentary:
Generally speaking invoke actions map to imperative APIs, where "auto" is an alias for "do the most common action". So if an invoker is pointing to a popover, the default action is to call
"auto" is the stand-in for when the attribute value is missing, so
"It depends". When it does, it will most certainly be specified. Specifically for a |
I think another way to think about this is that the invoker logic should (always?) execute an existing imperative algorithm/function. And those should already be doing the right thing. So for popover and dialog, the |
@hober, @plinss, and I discussed this today. We're broadly in favor of invokers because it unifies some existing interaction patterns. We feel it makes sense to have an We observe that a lack of additional arguments to invocations (or Having (A footnote from me: when we ask questions, like the one above about focus, we appreciate your helpful answers. We appreciate those answers being added to documentation even more.) |
Firstly I'd like to say thank you for taking the time to review this proposal and I want to apologise for the time it’s taken to respond, please don’t take this as a sign we don’t value the feedback.
Regarding the suggestion for an invoke() function, this was discussed we don’t believe this is needed at this time.
Custom elements can have their custom commands dispatched via calling dispatchEvent with the appropriate command event instantiated, see code snippet below.
Built-in actions will have an existing JavaScript function to achieve the same thing. Specifically in the case of popover these were recently updated to support supplying the invoker const customElement = document.querySelector(‘custom-element’);
const source = document.querySelector(‘#source’);
const commandEvent = new CommandEvent('command', {source: source, command: '--custom-action'});
customElement.dispatchEvent(commandEvent);
This was also discussed, we see that this would be usable but not necessary for v1. For v1 all browsers will ship the same set of commands so it’s not needed for feature detection. It’s worth also pointing out that you can do some level of feature detection using the command IDL attributes reflection, it only reflects valid or custom values, this should solve most of the use cases.
If we were to add something like this in future it would be good to hear from the TAG what API shape you would like to see. Should this be an isValidCommand(command) function, or should this be a method that returns an array of values? How contextual do you think the validation should be? e.g. Should toggle-popover be valid on a const button = document.createElement('button');
button.command = 'invalid-command-to-validate';
button.command === ''
button.command = 'close';
button.command === 'close'; |
As far as custom invokers, that makes sense. We discussed this and we're OK with this being something that gets added later. After all, it isn't that hard to add something like the following if it proves useful: Whatever.prototype.invoke = function(cmd, options) {
this.dispatchEvent(new CommandEvent(cmd, options));
} After doing some digging on the discoverability thing, we agreed that it isn't worth burdening you with solving a longstanding platform issue for this case. This is a pretty serious gap in our discoverability, but that's a shared responsibility. That said, I suspect that even if that problem were solved for other APIs, some of those solutions would not help with this specific API, given it's shape, so I'd encourage you to think about what |
こんにちは TAG-さん!
I'm requesting a TAG review of the "Invokers API", as described in the Open UI explainer.
Adding invoketarget and invokeaction attributes to
<button>
and<input type="button">
/<input type="reset">
elements would allow authors to assign behaviour to buttons in a more accessible and declarative way, while reducing bugs and simplifying the amount of JavaScript pages are required to ship for interactivity. Buttons withinvoketarget
will - when clicked, touched, or enacted via keypress - dispatch anInvokeEvent
on the element referenced byinvoketarget
, with some default behaviours.While there are many ideas for what those behaviours will be, for the initial implementation we want to ship:
popovertarget
).Further details:
showpopover
,hidepopover
,togglepopover
,showmodal
,close
andauto
. It seems as though these should include dashes, but we've reserved dashes for custom actions (see openui/open-ui#900 and openui/open-ui#969).You should also know that...
We are looking for help with resolving the naming of actions, and how we can best fit the existing system. We're explicitly interested in feedback from the TAG!
This works surrounds some larger work pieces, for example there is follow on work to add more actions, follow on work to add an
interesttarget
which will do the same but for hover/focus style interactions, and we are also looking to deprecatepopovertarget
in favour of this API. While we're not seeking review for those parts, I hope they can paint a broader context of what is planned here.We'd prefer the TAG provide feedback as:
🐛 open issues in our GitHub repo for each point of feedback
The text was updated successfully, but these errors were encountered: