Post

Two cool improvements are coming to <dialog> soon ™️. - button command/commandfor attributes to open dialogs without JS. - closedby attribute to enable light dismiss or disable close on esc (etc)

36 reposts165 likes

Awesome, I already knew about Invoker Commands but I’ve got a perfect use-case for `closedby` that I need right now: an age verification modal for a wine merchant!

Is there a shortcut? I’m currently using data-dialog=“open id” and it would be more ergonomic to continue using one attribute. command=“open:id” or similar would be great.

That was discussed as one idea, unfortunately it gets syntactically tricky. If you set .commandForElement to an element without an ID then it sets the attribute to an empty string. So you'd have to have a way to deal with that. It'd also be a novel syntax to parse, so we decided against it.

I'm not 100% on what we've ended up with either, naming and explicitness wise but I'm trying to not let perfect be the enemy of good.

I'm going to go with soon™️ to play it safe. Closedby is a newer proposal so might take longer but it's also a hopefully less contentious addition. Command is just invokers yes it's gone through a few revisions since the original plan. Hoping it will be merged into html spec really soon!

You can have custom commands where you can make your own microsyntaxes for that sort of thing. They do require JS but would still simplify the logic imo. Generally if the code needs an argument it probably suggests that's where JS should be used. The idea with this is to make simple things simpler.