The new stylable <select> element

We're finally getting a <select> element we can fully control with CSS! A bunch of other stuff needed to be added to the platform to make it work, and the good news is we can use a lot of them independently of <select>.

Resources:

Transcript
  1. Jake:I think I'm ready. I think I'm good to go.
  2. Surma:On a scale of 1 to 10, how rusty do you feel right now?
  3. Surma:You know, we're on a schedule with recording. Kinda.
  4. Jake:Are we?
  5. Surma:We've been pretty good. Like, plus minus a week or something.
  6. Surma:And yet I feel rustier than ever every time we do this.
  7. Jake:Yeah, I mean, we're a little bit behind compared to our usual schedule because, well, we both got ill.
  8. Surma:Yeah. Good.
  9. Jake:It wasn't Covid.
  10. Jake:Well, I don't know about that, because it knocked me out for a week.
  11. Jake:Like, I couldn't think properly. It had all the downsides of Covid, but without the validation.
  12. Surma:Ah, there is, like, a bit of, like,
  13. Surma:oh, it's Cove and everybody just nods in understanding, isn't it?
  14. Surma:I feel like, also, COVID is exempt from the man flu.
  15. Jake:Yeah. And, like, I know there are other illnesses out there.
  16. Jake:It's not like when Covid arrived, all the other illnesses felt so inadequate by comparison that they just vanished out of existence, right?
  17. Jake:So, I maybe had regular flu, right? I don't know.
  18. Jake:But I felt guilty not working because the little test was telling me, you're fine, mate.
  19. Surma:Any other flu. You get man flu labeled.
  20. Surma:Which, you know, maybe correctly so, I do not know.
  21. Jake:Exactly.
  22. Jake:Yes.
  23. Surma:But, yeah, I feel like, you're right!
  24. Surma:When you can say, I have COVID, everybody goes,
  25. Surma:oh, yeah, you just, you do your thing. You recover quickly.
  26. Jake:So, my start-up idea, and you can invest if you want, is a lateral flow test for everything.
  27. Jake:So, like, you get your two red stripes if...
  28. Surma:Any liquid hits the stick.
  29. Jake:Well, no, no, no, if you were ill enough to justifiably feel sorry for yourself and lie on your sofa.
  30. Surma:Right, so it's lateral flow for fragile masculinity.
  31. Jake:That's the rule.
  32. Surma:I like it. I'll invest.
  33. Jake:Exactly. Yeah.
  34. Jake:I guess it is a man flu or a person flu system.
  35. Jake:But, yeah, that just tells you, yeah, mate, you're ill. You're properly ill.
  36. Jake:Just take the day off. Go play PlayStation. Guilt-free. That's what I want.
  37. Surma:That seems, yeah, I want that in my life as well. Ship it.
  38. Surma:No, we should do an intro.
  39. Surma:You wanted to make this more professional.
  40. Surma:You told me off last time.
  41. Jake:Oh, we haven't even done the intro.
  42. Jake:Look, okay.
  43. Jake:Well, we've talked a bunch now.
  44. Surma:No, no, we're going to play the music.
  45. Jake:Are we going to edit this?
  46. Surma:And we're going to, people are going to hear me say,
  47. Surma:we should play the music now.
  48. Surma:Then we're going to play the music.
  49. Surma:And then we do the intro.
  50. Surma:We do like, you know, like some of the TV shows who, like, do the,
  51. Jake:No.
  52. Surma:like a little intro, then the actual theme plays.
  53. Surma:And then it goes like two weeks earlier.
  54. Surma:And then the actual story starts.
  55. Surma:And I think that's what we should do.
  56. Surma:Rope them in with a nonsense anecdote.
  57. Surma:That's totally how podcasts work, right?
  58. Jake:Fine. Roll the music.
  59. Jake:I heard my own voice going, do-do-do-do-do-do, like it was just nondescript music.
  60. Surma:Which music are you hearing in your head right now?
  61. Jake:You know that system you were talking about where, like, you know, they would have a bit of the show and then the intro sequence?
  62. Surma:Wow.
  63. Jake:And then that pattern actually came about from U.S. TV, where they would have an advert break straight after the intro.
  64. Surma:That's brutal.
  65. Jake:I know. I only learned this recently. I'm sure people in the U.S. were aware of it, but, you know.
  66. Jake:Anyway, you were about to do a professional intro, and I'm not going to stop you any longer.
  67. Surma:Ladies and gentlemen, welcome to OTMT.
  68. Surma:My name is Surma.
  69. Surma:And this is a podcast.
  70. Jake:My name is Jake.
  71. Jake:Yes, thanks, Shopify, for letting us do this, as usual.
  72. Surma:It is nice.
  73. Surma:Yeah.
  74. Jake:It's nice of them, isn't it? It's just nice. Everyone's nice.
  75. Surma:Yeah.
  76. Jake:Should we talk about the web now?
  77. Surma:Why not?
  78. Surma:Let's go.
  79. Jake:All right, all right.
  80. Jake:So, I wanted to talk about the new stylable select element on the web.
  81. Jake:It's something we've all wanted for years, 20 years, yeah.
  82. Surma:20 years.
  83. Surma:Yeah.
  84. Jake:And it's actually close now, like, for real.
  85. Jake:Like, there's an implementation in Chrome Canary, and it's ready for feedback.
  86. Surma:Ooh.
  87. Surma:But how stylable is stylable?
  88. Jake:It's happening.
  89. Surma:What?
  90. Jake:Like, completely.
  91. Jake:I know, I know.
  92. Jake:And it's not without its rough edges and weirdness, and I will get to those, because it's fun.
  93. Jake:But I do think it's actually a great thing, and part of the story, the interesting part of the story for me,
  94. Jake:is all of the little lower-level features that we've gotten along the way.
  95. Surma:So they, they, they did the bill.
  96. Surma:It's not just, you know, like,
  97. Surma:Scrolling to facts.
  98. Surma:Boom, high level.
  99. Surma:Nothing in between.
  100. Surma:You only can link to scrolling and do stuff.
  101. Surma:But did they actually build the layers in between an X?
  102. Surma:And I'm giving us those as well.
  103. Surma:That is nice.
  104. Surma:So basically, because I know this work has been going on for a long time, the kind of
  105. Jake:Exactly.
  106. Jake:I've counted 10 lower-level features that are usable outside of select,
  107. Jake:but are used by the select, or you would typically use it with the select thing,
  108. Jake:and were probably created with it in mind.
  109. Surma:hope I would have hearing that is that the select element is the guinea pig and the next
  110. Surma:ones will maybe, hopefully come about quicker because now the lower level primitives have
  111. Jake:Yes.
  112. Jake:Absolutely, and there's patterns that have been established.
  113. Surma:already been designed and established.
  114. Surma:I have so many questions, but I'm going to let you set the scene first.
  115. Jake:Oh, I'll set the scene.
  116. Jake:The select element.
  117. Jake:Look, we've all made one.
  118. Jake:You've seen them.
  119. Jake:We've coded them.
  120. Jake:You get a select element, and then inside, you've got a bunch of options,
  121. Surma:It selects things.
  122. Surma:Oh, I used to use it quite a lot.
  123. Jake:potentially in opt groups, you know, or not, whatever.
  124. Jake:The user presses the select button thing,
  125. Jake:Really?
  126. Jake:Yeah.
  127. Jake:Yeah, that's why it's rubbish, because you have to ctrl or shift click, right?
  128. Jake:That's why no one uses it.
  129. Jake:Why is that?
  130. Surma:Well, not, I haven't done recently, but I know because it suddenly turns from like a
  131. Jake:Because it's a weird thing.
  132. Jake:It's weird.
  133. Jake:It's weird.
  134. Surma:drop down into a box and you can like control or shift click multiple things, right?
  135. Jake:It's weird.
  136. Jake:It's weird.
  137. Jake:It's weird.
  138. Jake:It's weird.
  139. Jake:It's weird.
  140. Jake:It's weird.
  141. Jake:It's weird.
  142. Jake:It's weird.
  143. Jake:It's weird.
  144. Jake:It's weird.
  145. Jake:It's weird.
  146. Surma:Now that you say that, I don't even know what that looks like on mobile.
  147. Jake:Oh, that's a good point.
  148. Jake:I have no idea either, because no one uses it, because it's shite.
  149. Jake:Okay, but when it's a single select, it kind of renders like a dropdown.
  150. Jake:And the advantage of the way it works, it's very declarative,
  151. Surma:Yeah, infamously on iOS, you get one of the, that's still like one of them, like more skeuomorphic
  152. Jake:is the user agent can render it however it wants,
  153. Jake:and it tends to be rendered in a way that fits in with the operating system
  154. Jake:and with the device.
  155. Jake:Do they still do that?
  156. Surma:leftovers where it's almost like on little wheel drums where you select the number or
  157. Surma:the option that you want.
  158. Surma:I don't quote me on it, but I think so.
  159. Jake:That's interesting.
  160. Jake:And on Android, it does show as a kind of full screen-ish overlay, right?
  161. Jake:But even on desktop, it looks like part of the OS,
  162. Jake:and the popover thing can escape the iframe it's in.
  163. Jake:It can even escape the browser window it's in.
  164. Jake:Like, it's got these kind of superpowers by being sort of
  165. Jake:an operating system level kind of thing.
  166. Surma:Yeah.
  167. Surma:And the fact that it is looking like the operating system is actually what people often
  168. Surma:dislike because they have, you know, a whole design system that somebody painstakingly
  169. Surma:designed and implemented.
  170. Surma:And then somebody wants to select and they're like, well, can't do anything about that.
  171. Jake:Do you want an ancient fact?
  172. Surma:Oh yeah.
  173. Jake:I feel like this should be a recurring segment.
  174. Surma:Grandpa Jake tells war stories from Brazzer land.
  175. Jake:Yeah, let's go with that.
  176. Jake:Welcome to Grandpa Jake tells stories from Browserland.
  177. Jake:Excellent, cool.
  178. Jake:In Internet Explorer 6 and earlier, select elements were rendered
  179. Jake:by the operating system, not by the browser engine,
  180. Jake:and it was a separate rendering pass, right?
  181. Jake:Meaning select elements were on top of everything else,
  182. Jake:like the z-index was.
  183. Surma:Lovely.
  184. Surma:Oh, it's like the rock, paper, scissors.
  185. Jake:The only thing that could render on top of a select were these other things
  186. Jake:that kind of had this same second pass logic,
  187. Jake:one of which was an iframe.
  188. Jake:Or rather, the bits of the iframe that intersected with the select,
  189. Jake:like the select wouldn't render there.
  190. Jake:But IE6 did have a code path to allow things to render
  191. Jake:on top of iframes.
  192. Jake:It was kind of like that logic was just missing from select,
  193. Jake:but it was there for iframe.
  194. Surma:Of rendering order.
  195. Jake:Well, here's the thing.
  196. Jake:So if you wanted to render a div on top of a select,
  197. Jake:like you were creating an overlay or a popup or something like that,
  198. Jake:what you would do is put an empty iframe behind the div
  199. Jake:to prevent the rendering of the select underneath.
  200. Surma:That's brilliant.
  201. Surma:I love that so much.
  202. Jake:That was another episode of Grandpa Jake's Ancient Browser Stuff.
  203. Jake:I can't remember what we were calling it.
  204. Surma:That is genuinely amazing.
  205. Surma:I love that.
  206. Jake:So that's select in general.
  207. Jake:The bad part is you can't control the styling
  208. Jake:because they're rendering differently everywhere,
  209. Jake:so how even would you?
  210. Jake:So if you wanted a dropdown that looked slightly different,
  211. Jake:you were creating your own from scratch.
  212. Jake:Even if you just wanted an image inside the options,
  213. Jake:like a flag for language select or whatever, some kind of icon,
  214. Jake:no, you were creating from scratch,
  215. Jake:and that included all of the accessibility stuff,
  216. Jake:which is really, really hard,
  217. Jake:and keyboard interaction is really hard.
  218. Surma:Well, no, you just don't do the accessibility.
  219. Surma:The accessibility stuff that we have seen and all the components people have written
  220. Surma:that do custom selects, isn't it?
  221. Jake:Exactly.
  222. Surma:It's like instantly a world of awful because suddenly you are in get bounding, climbing
  223. Jake:Exactly.
  224. Surma:rack territory, absolute positioning, Z index fighting, and all that jazz just to get something
  225. Surma:that really, you know, I just wanted an icon next to my dropdown option.
  226. Jake:Yeah, and you're right. No one gets it right.
  227. Jake:So the Open UI group, they set out to solve this,
  228. Jake:that they're going to create a select element
  229. Jake:that had all of the accessibility and interactions built in
  230. Jake:and allowed for the full and predictable styling.
  231. Jake:And it's taken years, but we are nearly there.
  232. Jake:Can't rush art.
  233. Jake:Can't rush browser standards, that's for sure.
  234. Jake:So people who might have looked at this effort
  235. Jake:over the decade or whatever,
  236. Jake:they might have seen that it was going to be proposed
  237. Jake:as a new element, like custom select.
  238. Jake:I can't remember what it was, but that's dead.
  239. Jake:That's dead now.
  240. Surma:Oh, but it also means that they have to kind of like shoehorn all the, like, you know,
  241. Jake:The new plan is to enhance the existing select elements,
  242. Jake:and this is great because it means
  243. Jake:these new fancy custom-style select things,
  244. Jake:they fall back to regular select.
  245. Surma:the all knobs and levers onto the existing syntax because it needs to gracefully degrade
  246. Surma:slash progressively enhance for sure.
  247. Jake:Yes, so it means your rich content and your options
  248. Jake:will just fall down to text content,
  249. Jake:which you have to be careful with.
  250. Jake:But I do think it's actually one of the impressive things
  251. Jake:about this effort is how they've managed to thread the needle.
  252. Surma:It's very impressive.
  253. Jake:Like, yeah, they've looked at what browsers will accept
  254. Jake:but ignore inside select and option elements
  255. Jake:and made it work.
  256. Jake:Yeah, I think it's good.
  257. Jake:So you need an opt-in, right?
  258. Jake:Because you need a way to switch it from a normal select element
  259. Jake:into this whole new world.
  260. Jake:Yeah.
  261. Jake:You know what?
  262. Jake:We're going to talk more about these little opt-in switches.
  263. Jake:I feel like they are multiplying on the platform.
  264. Jake:Yeah, I'm going to cover a few of them just in this episode.
  265. Jake:So if we think about a select,
  266. Jake:it's kind of two top-level parts, right?
  267. Jake:There's a button, and that's the bit on the page
  268. Jake:that displays the currently selected option.
  269. Jake:But it's just a button, right?
  270. Jake:It doesn't look like an HTML button,
  271. Jake:but it's a thing you focus and a thing you press.
  272. Jake:It's a button.
  273. Jake:If you give that, via the select element in CSS,
  274. Jake:appearance-base-select,
  275. Jake:then it changes the mode
  276. Jake:and falls to a cross-browser version of that button
  277. Jake:that is, like, agreed styling.
  278. Surma:Is this the first occurrence of appearance or did we have that somewhere else before?
  279. Jake:Appearance is there already, but don't ask me what it does.
  280. Jake:It's one of those ones that has always been a bit of an enigma to me
  281. Jake:because, yeah, there's, like, appearance-non, and it...
  282. Jake:I don't know. It does something.
  283. Jake:I think it might be something that kind of appeared in ancient days,
  284. Jake:and it's sort of in a standard noun.
  285. Jake:Do you know what?
  286. Surma:Wait to double check.
  287. Surma:Is this an attribute or a CSS property?
  288. Jake:CSS property.
  289. Jake:So you can apply it to all your selects.
  290. Jake:So, yeah, once you put that CSS on there,
  291. Jake:you get this, like, cross-user-agent, cross-device button.
  292. Jake:That kind of looks like a very basic dropdown-select button
  293. Jake:that we all know and love.
  294. Jake:You know, it's got the little arrow.
  295. Jake:It's got the selected item in it.
  296. Surma:I instantly wish that they would have just called it base because I would love to just
  297. Surma:do in my style sheet star appearance base that all UI controls will use that base appearance
  298. Surma:if once we have it for every UI element.
  299. Jake:And your intent there is exactly why they haven't done that.
  300. Jake:So if they said, like, right,
  301. Jake:star-appearance-base means reset all of the form controls,
  302. Jake:they're not going to ship that
  303. Jake:for all of the form controls straight away.
  304. Jake:So they're going to ship that with select, like, or whatever.
  305. Jake:But then that style is out there,
  306. Jake:and then when browsers come to do that for date picker
  307. Jake:or, you know, colour picker or whatever or some other control,
  308. Jake:they're going to ship, and your page is going to change
  309. Jake:and probably going to change in ways you don't want.
  310. Jake:So it prevents a sort of future compact problem.
  311. Surma:As long as they ship something like that, once every form element has a cross browser
  312. Jake:I guess, whether that will ever happen or not,
  313. Surma:standardized look, all new formalins should now have a cross.
  314. Jake:because you can always add new form elements in the future,
  315. Jake:but I guess if they've done...
  316. Jake:Yeah, if they do that for all new form elements as well.
  317. Surma:Like I think I think that's really nice that now there is basically the signal like we
  318. Surma:are going to give every standardized interaction element a cross browser agreed look.
  319. Surma:So you move away from it looks correct for the operating system because I think the benefit
  320. Jake:Yeah, I agree.
  321. Surma:of that was never really as big as maybe originally hoped.
  322. Surma:I could see, you know, like in a world with, you know, installable web apps, there was
  323. Surma:an element of it's nice that it looks like a native counterpart, but actually almost
  324. Surma:all apps decide their own button design.
  325. Surma:So I think, yeah, this is the better direction, in my opinion.
  326. Jake:The other part of the select is the popover,
  327. Jake:like the thing that appears when you press the button
  328. Jake:and goes away when you select an option
  329. Jake:or press escape or whatever.
  330. Jake:So you need to opt into the standard rendering of that separately.
  331. Jake:And that is done via a pseudo element hanging off the select,
  332. Jake:which is colon, colon, picker,
  333. Jake:and then in open brackets, or within brackets, select.
  334. Jake:So it's kind of like a pseudo element function kind of thing.
  335. Surma:That was bad.
  336. Jake:And again, this is for the same reason for, you know,
  337. Jake:they don't want people saying, like, all pickers,
  338. Jake:I want all pickers to be base style.
  339. Jake:Like, they want to force you to be saying,
  340. Jake:I want this to happen for select.
  341. Surma:Right.
  342. Jake:Yeah, and again, you do appearance base select on that.
  343. Jake:The nice thing about it being split is you can
  344. Jake:just opt into controlling the button
  345. Jake:and stick with the operating system picker.
  346. Jake:You cannot do it the other way around.
  347. Jake:You can't just opt into the picker without opting into the button.
  348. Surma:That kinda makes sense, I suppose.
  349. Jake:I guess it comes down to, like, you know,
  350. Jake:if you're just controlling the picker, I don't know.
  351. Jake:I don't know. They probably have some good reasons for it.
  352. Jake:But yeah, fair enough. I'm fine with that.
  353. Jake:So let's talk about popover.
  354. Surma:I was gonna ask, don't we have a popover element
  355. Surma:that recently got designed or something, or am I making stuff up?
  356. Jake:You are not making stuff up. It's a popover attribute.
  357. Surma:Nope.
  358. Surma:Uggghhh.
  359. Jake:And so, like, almost every element can now have a popover attribute.
  360. Jake:I think it maybe is actually all elements, but, you know,
  361. Jake:it only really matters on elements that render.
  362. Jake:And that means it can be shown as a popover
  363. Jake:by calling .showPopover.
  364. Jake:That means it appears on top of everything else.
  365. Jake:And that uses another feature of the web platform
  366. Jake:called the top layer,
  367. Jake:which I think was originally created
  368. Jake:to support full-screen elements,
  369. Jake:but it's since used by dialogue elements
  370. Jake:when they're in modal mode.
  371. Surma:Right.
  372. Jake:We use it for view transitions,
  373. Jake:and popovers appear there as well.
  374. Jake:There's probably some other features too.
  375. Jake:They come with, like, focus logic
  376. Jake:to control focus in expected ways.
  377. Jake:You can use escape to close them,
  378. Jake:and it returns focus. It's pretty smart.
  379. Surma:And you have this anchor positioning as well to position the popover adjacent to a specific
  380. Surma:corner of another element or something?
  381. Jake:Yes. So the popover bit...
  382. Jake:So I should say there's also, on a button element,
  383. Jake:you can add a popover target,
  384. Jake:which means, like, clicking the button
  385. Jake:will toggle or show or hide.
  386. Jake:You can control that as well.
  387. Jake:Like, that will control the popover.
  388. Jake:And that will also create an accessibility link
  389. Jake:between the button and the popover.
  390. Surma:That's nice.
  391. Jake:There's a great article by Hidde de Vries
  392. Surma:Very good.
  393. Jake:and Scott O'Hara, which covers all of the accessibility stuff
  394. Jake:under the hood here, which I'll link to
  395. Jake:because it's really good.
  396. Jake:So those features are available cross-browser,
  397. Jake:like, today.
  398. Jake:But you just mentioned anchoring,
  399. Jake:which, yes, like,
  400. Jake:you want the popover to be linked to the button,
  401. Jake:typically, but which side of the button?
  402. Jake:Well, that's kind of down to you.
  403. Jake:And maybe you want it to, like,
  404. Jake:appear on the side that has the most space
  405. Jake:or, like, favor one side,
  406. Jake:but if it would go out of view, flip it to another side.
  407. Jake:And yes, CSS anchor positioning
  408. Jake:gives you that capability.
  409. Jake:Only in Chrome right now, but it is in stable.
  410. Jake:And you can use that on any element.
  411. Jake:That's the nice thing.
  412. Jake:So the popover stuff, the anchoring,
  413. Jake:these are features that you don't...
  414. Jake:They don't have to have anything to do with select,
  415. Jake:but it is the things that select uses internally
  416. Jake:with sensible defaults,
  417. Jake:and you can modify them
  418. Jake:and use them separately.
  419. Surma:Yeah, that's really really nice, really nice layering.
  420. Jake:So any elements that you put
  421. Jake:inside the select,
  422. Jake:they end up in the popover.
  423. Jake:Well, not just options.
  424. Surma:That makes sense.
  425. Jake:It means you can use divs as well
  426. Jake:to help with layout or whatever.
  427. Surma:So in this opt-in world is then the popover just like basically an element and I can use
  428. Surma:you know relative positioning, absolute positioning, all that jazz?
  429. Jake:It will always be in the top layer,
  430. Jake:so giving it relative positioning
  431. Jake:isn't going to get you anything,
  432. Jake:because everything is sort of...
  433. Jake:Yes, you can. Absolutely.
  434. Surma:What if I wanted to arrange my select options in a circle?
  435. Jake:And you're whatever kind of layout you want,
  436. Jake:you can do there.
  437. Jake:So there is a downside to this,
  438. Jake:and, like, you get all of that CSS control,
  439. Jake:you get to do what you want with it,
  440. Jake:but because it's just in the top layer,
  441. Jake:and because you have that control,
  442. Jake:it can't escape the iframe it's in,
  443. Jake:and it can't escape the browser window,
  444. Jake:because that would be a security issue,
  445. Jake:rendering stuff in another origin,
  446. Jake:or you're rendering stuff outside of the browser.
  447. Surma:Right.
  448. Surma:I guess that makes sense and I think the feasible workaround which I assume is handled
  449. Surma:automatically that you know if the button with a popover is at the bottom end of the
  450. Surma:screen the popover will open upwards rather than downwards.
  451. Surma:So it's really only the scenario that is now problematic, it wasn't problematic before
  452. Jake:Exactly.
  453. Surma:if you have a tiny tiny iframe.
  454. Jake:Or a tiny, tiny browser window, or something like that.
  455. Jake:Yeah, and so CSS anchoring gives you that,
  456. Jake:you know, preference of positioning,
  457. Jake:all of that you control,
  458. Jake:and there are sensible defaults.
  459. Jake:Yeah, so it's a kind of minor thing,
  460. Jake:but it is a notable difference
  461. Jake:between, like, the new world
  462. Jake:and the old select implementation.
  463. Jake:Option elements still represent your options,
  464. Jake:but they can contain rich content,
  465. Jake:so images, you know, you can format the text,
  466. Jake:you can add divs to hang styles off,
  467. Jake:you can do whatever you want.
  468. Jake:There is a checked pseudo class on options,
  469. Jake:and by default that causes the before pseudo element
  470. Jake:to contain a tick.
  471. Jake:I think that might change,
  472. Jake:that's something that's currently being discussed,
  473. Surma:So again, in my circular layout, how is keyboard input handled?
  474. Jake:but again, you can override all of that.
  475. Jake:Even if that is what lands in the user agent stylesheet,
  476. Jake:you can override it to change something,
  477. Jake:you know, be whatever.
  478. Jake:It is not.
  479. Jake:Well, yes, you're absolutely right.
  480. Surma:You get up and down, I suppose, right?
  481. Jake:So you get the accessibility stuff for free,
  482. Jake:you get keyboard stuff for free,
  483. Jake:but you just get up and down.
  484. Jake:So if you have arranged your items in a circle,
  485. Jake:or in a grid, or horizontally,
  486. Jake:which a lot of the demos are doing,
  487. Jake:because it's cool and new,
  488. Jake:a lot of them don't work.
  489. Jake:Like, you would have to go with JavaScript,
  490. Jake:and when left or right is pressed,
  491. Jake:when you're on this particular option,
  492. Jake:call focus on a particular different option.
  493. Surma:I think it's fine.
  494. Surma:I think, you know, solving all of these things in one go is probably super hard.
  495. Surma:I think going so the fact that you can select any option with a keyboard, that's the most
  496. Surma:important thing.
  497. Surma:The fact that it sometimes is visually unintuitive, like I wouldn't say it doesn't work, it's
  498. Surma:just unintuitive to go up down when you visually go left and right.
  499. Jake:Yeah, that's a fair point.
  500. Jake:By default you will be able to scroll through the items,
  501. Jake:it might just not be the most expected buttons
  502. Jake:that you will press.
  503. Surma:And maybe at some point there is, you know, CSS has this whole spatial navigation thing
  504. Surma:going on, maybe that can be connected at some point, but I'm super happy that they are taking
  505. Surma:this approach for the first release of this, where you're just like, you know it works
  506. Surma:and it is a massive leap to what it was before, so, you know, it's good.
  507. Jake:Yeah, I'll link to the effort,
  508. Jake:the previous effort for spatial navigation,
  509. Jake:there's a spec written,
  510. Jake:I haven't looked at the spec,
  511. Jake:so I don't know anything about it,
  512. Jake:but I know it was done by LG folks,
  513. Jake:because of course they're on a TV,
  514. Jake:and they've got up, down, left, right on a remote,
  515. Jake:so spatial navigation is really beneficial to them.
  516. Jake:So there was spec efforts,
  517. Jake:but it hasn't really been touched in,
  518. Jake:I think, three years.
  519. Jake:So that's one of the features
  520. Jake:we haven't got out of this.
  521. Jake:Alright, that's the popover.
  522. Jake:The button.
  523. Jake:So once you've done the opt-in,
  524. Jake:there's a standard button that you can style,
  525. Jake:but you can do more.
  526. Jake:I said before that anything inside the select element
  527. Jake:appears in the popover,
  528. Surma:Oh, so that allows you to like to model the state change between is the popover open or
  529. Jake:there is one exception to that rule,
  530. Jake:and that's if you put a button element
  531. Jake:as a direct child of the select.
  532. Jake:Then it becomes the button.
  533. Jake:Like the UA rendered one is gone,
  534. Jake:and just that button you've put in
  535. Jake:is the button now.
  536. Jake:Well done.
  537. Jake:Well yes, so
  538. Jake:you can use the
  539. Jake:select open and closed
  540. Jake:pseudo classes for that,
  541. Jake:and then control your button
  542. Jake:within there to flip
  543. Jake:the arrow position,
  544. Jake:or some of the colors, or whatever state.
  545. Jake:Yeah, that's all available to you.
  546. Jake:And those open and closed pseudo classes
  547. Jake:are a relatively new thing as well.
  548. Jake:I don't know if they were created directly for
  549. Jake:select, but they've been added
  550. Jake:to select for this.
  551. Jake:I think they were also on details.
  552. Surma:So you sounded like it wasn't the intention that you can have basically one button look
  553. Surma:for open, one button look for closing.
  554. Surma:What is the intended use case behind replacing the original button with another button?
  555. Jake:Well, it's just that you can do
  556. Jake:whatever you want with it.
  557. Surma:Ah, okay.
  558. Jake:So with the previous one,
  559. Jake:it's the content that the UA comes up with,
  560. Jake:but sure, you can change the background color,
  561. Jake:the border, and all of that.
  562. Jake:But with this, you can put
  563. Jake:whatever text, images,
  564. Jake:blah, like,
  565. Jake:it's yours to do whatever
  566. Jake:you want with.
  567. Surma:Right.
  568. Surma:I mean, it's really good flexibility.
  569. Surma:How do events work in that moment?
  570. Jake:Well, you've still got the
  571. Jake:select element is there.
  572. Jake:So whether the button
  573. Jake:gets a click event, or whether that's
  574. Jake:like
  575. Jake:stop propagation,
  576. Jake:stop immediate.
  577. Surma:Because I'm thinking about, you know, in Preact, if people put their on click on one of the
  578. Jake:...
  579. Surma:buttons rather than the surrounding selects or like only on one button and then they replace
  580. Surma:it, but then obviously the other button doesn't have a click listener.
  581. Jake:Well, you shouldn't have to add a click
  582. Jake:listener to the button.
  583. Jake:Because there's no real call to,
  584. Surma:No, but maybe you want to do something in response to a click, right?
  585. Jake:because the browser will automatically hook it up
  586. Jake:to the picker.
  587. Jake:Oh yeah, so that should work.
  588. Jake:Whether if you prevent default on the click,
  589. Jake:whether it stops the popover
  590. Jake:appearing or not, I don't know.
  591. Jake:It feels like it should.
  592. Jake:So I would expect you to get a click on the button,
  593. Jake:and then obviously it bubbles up to the select as well.
  594. Surma:I guess I was asking if I put an on click listener on the one button and then this replace
  595. Surma:mechanism kicks in.
  596. Surma:Once it's open, I would have to add another click listener to the other button.
  597. Jake:Oh, no, no, there's only one button.
  598. Jake:I think this is maybe
  599. Surma:Oh, yes.
  600. Jake:where there's a confusion.
  601. Surma:I think now I follow.
  602. Surma:So yeah, we should rewind what you were saying.
  603. Surma:Let me, let me try and see if I got this.
  604. Jake:...
  605. Surma:If I understood it right now, you can put a button as a direct child of the select to
  606. Surma:take complete control of the look of the button.
  607. Surma:I understood that button only comes in action once the original button has been clicked.
  608. Jake:Yes, that's where we got confused.
  609. Surma:Right, so that's basically a special rule for if there is direct child button that becomes
  610. Jake:No, it's just the thing that appears on the page,
  611. Jake:the default version of that is gone,
  612. Jake:and it is now just your button.
  613. Jake:Is it?
  614. Surma:that is your signal as a developer.
  615. Jake:...
  616. Surma:I want to take control of the select to open the button myself.
  617. Jake:Yes, exactly that.
  618. Jake:And are you ready for where
  619. Jake:things start to get really weird?
  620. Surma:Oh, yes, absolutely.
  621. Surma:The clone of the option element was like, that is actually cool.
  622. Jake:There's a new element
  623. Jake:called selected option.
  624. Jake:All one word.
  625. Jake:Well, no spaces, because it's a tag name.
  626. Jake:If you put
  627. Jake:one of those in your button element,
  628. Jake:it will receive
  629. Jake:a clone of the contents
  630. Jake:of the option element
  631. Jake:that's selected.
  632. Jake:Well, the clone of the contents
  633. Surma:Yeah, that is actually kind of clever.
  634. Jake:of the option element that's selected.
  635. Jake:Sorry, I have to do
  636. Surma:Yeah, that has a selected property set to true.
  637. Jake:some verbal gymnastics here, because
  638. Jake:it means we've got a
  639. Jake:selected option element,
  640. Jake:and a selected option element.
  641. Jake:So I'm trying to find ways to...
  642. Jake:Because there's the thing with the tag name,
  643. Jake:selected option, and then there's the thing
  644. Jake:with the tag name, option, which is selected.
  645. Jake:So...
  646. Surma:Interesting.
  647. Jake:Excuse me while I sound not entirely human
  648. Jake:while I try and make
  649. Jake:the two sound very different.
  650. Jake:It's a light DOM clone
  651. Jake:of the contents.
  652. Jake:I said in previous episodes
  653. Jake:it's a bit weird and unusual for elements
  654. Jake:to modify their own attributes
  655. Jake:in response to user interaction,
  656. Jake:but it does happen with dialogue
  657. Jake:and details. They both
  658. Jake:add and remove their open attribute.
  659. Jake:There's also the
  660. Jake:hidden attribute, if you set that to
  661. Jake:if found.
  662. Surma:Yeah, I'm surprised that there wasn't.
  663. Jake:That's an indication to the browser that if you
  664. Jake:Control-F and
  665. Jake:it thinks the content is inside
  666. Jake:that element, it will
  667. Jake:remove the hidden attribute automatically
  668. Jake:from that element. So, you know,
  669. Jake:there are cases where browsers
  670. Jake:will modify elements themselves.
  671. Jake:It's just very rare
  672. Jake:and weird. But this takes it to a whole
  673. Jake:new level because it's a whole
  674. Jake:clone in the light DOM that's sort of
  675. Jake:dumped into this other element.
  676. Surma:Maybe there were attempts and it didn't work out, but my immediate thought would have been
  677. Surma:slots.
  678. Surma:Right?
  679. Surma:Like, like in Shadow Dome, but maybe we can have slots outside Shadow Dome, because that
  680. Surma:would have also maybe made sense here?
  681. Jake:So there isn't the concept
  682. Jake:of projecting an element into two places.
  683. Jake:And that's
  684. Jake:the problem we've got here. It's because when
  685. Jake:you've selected an element and you open
  686. Jake:the select again, you're seeing
  687. Jake:that item in two places. You're seeing it in
  688. Jake:the popover and
  689. Jake:in the button.
  690. Surma:That's true.
  691. Jake:And there is the
  692. Jake:elements function in CSS, which only
  693. Jake:Firefox supports, which lets you create
  694. Jake:a bitmap copy of another
  695. Jake:element, but that means it can't
  696. Jake:be separately styled.
  697. Jake:Whereas this full clone can be
  698. Jake:independently styled. It can receive
  699. Jake:its own events.
  700. Surma:I was just gonna say, it is actually quite flexible, almost elegant, in that if an option
  701. Jake:...
  702. Jake:...
  703. Surma:is the selected one, you can style it separate, you can style the appearance of inside the
  704. Jake:...
  705. Jake:...
  706. Surma:select drop-down button thingy separately, because it is now a full clone.
  707. Jake:...
  708. Jake:...
  709. Jake:Exactly. But it gets funkier.
  710. Jake:The current plan, and this is under
  711. Jake:active discussion, is
  712. Jake:that if you modify
  713. Jake:the DOM of the option that's selected,
  714. Jake:it triggers the cloning steps
  715. Jake:again synchronously.
  716. Jake:So if you create a div
  717. Jake:and you put it in the
  718. Jake:option that's selected, and you give it
  719. Jake:a class name, and you give it some
  720. Jake:text, and you
  721. Jake:change the inline style,
  722. Surma:Of course, you wanna immediately argue it doesn't have to be synchronous, but I guess
  723. Jake:that's how many? One, two,
  724. Jake:three, four. That's four
  725. Jake:modifications. So that's four times
  726. Jake:the entire contents of that option
  727. Jake:is cloned and inserted
  728. Jake:into the selected option element, replacing
  729. Jake:whatever content was there. Four
  730. Jake:whole clones.
  731. Surma:for certain logic, it might have to be.
  732. Jake:Right, and that's one of the things
  733. Jake:they're discussing, that should it be debounced,
  734. Jake:but things are sort of tending towards synchronous
  735. Jake:right now. But it also means that if you're
  736. Jake:animating something in the selected
  737. Jake:option using, like, GreenSock, or
  738. Jake:Anime.js, whatever, these libraries
  739. Jake:they modify the style object
  740. Jake:every frame, which is
  741. Jake:reflected to the style attribute,
  742. Jake:which is a DOM change, which is going to trigger
  743. Jake:the cloning operation every frame.
  744. Jake:And it's not just of the element you're modifying,
  745. Jake:it's everything in the
  746. Jake:option.
  747. Surma:But animation is always performance foot gun work, like people who do this need to know
  748. Surma:what they're doing, right?
  749. Surma:Like I am firmly of the opinion to give sharp tools to developers, let them run with scissors.
  750. Jake:Well, this is the thing, and if you were
  751. Jake:animating rotation and opacity,
  752. Jake:that's two writes to the style object,
  753. Jake:which is two writes to the style attribute,
  754. Jake:so that's two DOM modifications
  755. Jake:which triggers the cloning algorithm twice
  756. Jake:per frame, and
  757. Jake:on and on it explodes, you know?
  758. Jake:So,
  759. Surma:Yes.
  760. Jake:also, if you've got a CSS animation
  761. Jake:on an element,
  762. Jake:that starts when the element
  763. Jake:is, like, mounted.
  764. Jake:Like, when it's in the document.
  765. Surma:I was gonna ask because, you know, what about, you know, old school animated GIFs or even
  766. Jake:And if this thing is being recreated
  767. Jake:a lot, people, like, using
  768. Jake:React might have experienced this, the CSS
  769. Jake:animation will appear to reset,
  770. Jake:because it's a new element. And
  771. Jake:if it's a custom element that has,
  772. Jake:that's going to perform a fetch on construction
  773. Jake:or insert, like, this is going to be happening
  774. Jake:because of the clone, it's going to be happening
  775. Jake:time and time again.
  776. Surma:you know, video tags?
  777. Jake:Oh, exactly, yeah, you'll lose,
  778. Jake:and that's the thing, if
  779. Jake:any of the state is not represented
  780. Jake:by attributes, such as a canvas,
  781. Jake:such as the video playback position,
  782. Jake:then that's going to be lost.
  783. Jake:So, yeah,
  784. Jake:have fun. I think it's okay,
  785. Jake:the cloning thing, but I
  786. Jake:think the way it clones everything
  787. Jake:on any modification
  788. Jake:synchronously, one of those things needs to
  789. Jake:change. It's not quite right.
  790. Jake:I would prefer a pattern where
  791. Jake:if you modify something in the selected
  792. Surma:Now, here's a curveball of doom.
  793. Jake:option, it should make the
  794. Jake:same change on its related clone.
  795. Surma:Remember a couple episodes ago when we were talking about VDOM in the browser?
  796. Jake:Yes.
  797. Surma:What if instead of doing a full clone and effectively overwriting the child tree, it
  798. Surma:would do a VDOM diff and actually only change the attributes and properties?
  799. Jake:Yeah, that's a big
  800. Jake:curveball. I just think it would be simpler to say,
  801. Jake:like, it knows when it's cloned everything,
  802. Jake:and it can map, you know,
  803. Jake:the contents of the option to its clones.
  804. Jake:So if you edit an attribute
  805. Jake:in the selected option,
  806. Jake:it just sets the
  807. Jake:same attribute, the same name on the clone.
  808. Surma:So like basically replace the actions that are being done in one element to the other
  809. Surma:element, which is kind of, it's kind of what I was saying.
  810. Surma:It's just like, I saw the bridge to like, you know, VDOM diffing, which is the same
  811. Surma:effect, just more complicated, but yeah, true, yes.
  812. Jake:We've done this in Shopify, right?
  813. Jake:This is how Shopify extensions work.
  814. Jake:Something happens in the...
  815. Jake:We've got a virtual DOM in a worker.
  816. Jake:It's not a virtual DOM in the React sense.
  817. Jake:It feels like a real DOM, but when
  818. Jake:you do stuff in there, it's replaying the actions
  819. Jake:somewhere else, like
  820. Jake:through a security layer.
  821. Jake:I think that's what should happen.
  822. Surma:And maybe it will, I suppose in terms of, you know, with my very basic specking head
  823. Surma:on, a shallow or a deep clone is much easier to spec right now when they're already trying
  824. Jake:No.
  825. Surma:to spec all the other stuff, then also inventing, because that's not a thing anywhere on the
  826. Surma:platform, right?
  827. Jake:No. I mean, this whole
  828. Jake:cloning thing is new anyway. I mean,
  829. Jake:cloning isn't new, but doing that on
  830. Jake:user interaction is new.
  831. Jake:But yes, there is an existing algorithm
  832. Jake:for cloning elements, so
  833. Jake:they're leaning really heavily on that. So it would
  834. Surma:Maybe it's a step to, you know, maybe it's something they do, let's post MVP kind of
  835. Jake:be a lot more spec work to do the, you know,
  836. Jake:synchronizing the two trees,
  837. Jake:but it's not a lot. Like, as I've written
  838. Jake:it before, it's not...
  839. Jake:It's okay. It's more than what they've
  840. Jake:got currently, but I think it would remove
  841. Jake:a foot gun. Maybe.
  842. Surma:thing.
  843. Surma:I would understand if, if they did that, but.
  844. Jake:But I would say the good news
  845. Jake:is this is entirely opt-in.
  846. Jake:Using this selected option thing,
  847. Jake:you could say, well, I'm using
  848. Jake:React, so I'm just going to listen for
  849. Jake:the onChange event on the select,
  850. Jake:and I'm going to update the contents of my button.
  851. Jake:You know, and in
  852. Jake:that case, you're not limited to
  853. Jake:the DOM structure of the
  854. Jake:option. You can do whatever
  855. Jake:you want, and it's fine.
  856. Jake:So,
  857. Jake:and I think that's probably what I would do
  858. Jake:if I was using a framework already, but
  859. Surma:Yeah, and it's really nice that they have a pattern where it's opt-in, like you can
  860. Jake:whatever. It's nice that there
  861. Jake:is a non-JavaScript version there.
  862. Surma:choose to do the selected option tag, or if you just don't have it, then none of this
  863. Surma:is a problem because you either don't want the select option to be shown, which would
  864. Jake:Exactly.
  865. Surma:be a bit odd, or you're taking matters into your own hands.
  866. Jake:But that's not all,
  867. Jake:right? Let's say you want
  868. Jake:your fancy new select to animate.
  869. Jake:So, a basic thing for it to do would
  870. Jake:be to animate from height zero to
  871. Jake:its full height.
  872. Jake:You could do this as a clip path, but let's say we're
  873. Jake:just going to animate the height so the
  874. Jake:box shadows and the borders do the
  875. Jake:right thing, whatever, and we'll, you know,
  876. Jake:optimize the layout so it's not too bad.
  877. Jake:You could slap a CSS animation
  878. Jake:on the popover element.
  879. Jake:CSS animations run when an element appears,
  880. Surma:Wait, with CS animations, if I just say just the only keyframe I specify is from, oh, interesting.
  881. Jake:so you could do that.
  882. Jake:But you can't animate to an intrinsic
  883. Jake:size in CSS.
  884. Jake:Like, you can't animate to height auto.
  885. Jake:You can't animate to height
  886. Jake:minContent or fitContent or
  887. Jake:maxContent.
  888. Jake:It doesn't work.
  889. Surma:I did not know that.
  890. Jake:Yeah, it needs to be a number
  891. Jake:at the other end for it to work.
  892. Jake:Except now you can,
  893. Jake:and there is an opt-in, another opt-in.
  894. Jake:Are you ready? In CSS,
  895. Surma:Wait, is that the CSS function or property or?
  896. Jake:if you do interpolate-size
  897. Jake:colon
  898. Jake:allow-keywords,
  899. Jake:ding ding, that's it.
  900. Jake:And this one
  901. Jake:inherits, so you can just put it on root
  902. Jake:and be done with it.
  903. Jake:Now it just works.
  904. Jake:There's also
  905. Jake:calcSize,
  906. Jake:which you can say, like,
  907. Jake:yes, sorry, it is a CSS function.
  908. Jake:You're right. And it means you can say,
  909. Surma:Ah.
  910. Jake:like, give me autoHeight divided by
  911. Jake:2, or multiplied by 2, or
  912. Jake:minContent.
  913. Surma:That is lovely.
  914. Surma:Oh, that's going to be very useful in so many places.
  915. Jake:Yes. So there's sort of two ways to do
  916. Jake:the same thing. Like a simple way,
  917. Jake:and then a way that lets you do
  918. Jake:maths.
  919. Surma:That then together with clamp and all those shenanigans, is it always in reference to
  920. Surma:the element that it's being used on, or could I even do calc size on like from another element
  921. Jake:It's the same element,
  922. Surma:and use the result?
  923. Surma:Nah, that's fine.
  924. Jake:unfortunately.
  925. Surma:That makes sense.
  926. Surma:I guess otherwise you have the same problem as they did with resize observer, you could
  927. Jake:Yeah. You might be able to,
  928. Surma:have circular layout dependencies.
  929. Surma:Oh, that's fine.
  930. Jake:I guess you could do it relative to a parent
  931. Surma:That makes sense.
  932. Surma:I guess otherwise you have the same problem as they did with resize observer, you could
  933. Jake:by the parent setting a custom property,
  934. Surma:
  935. Jake:but...
  936. Jake:Yeah, that's always the problem, isn't it?
  937. Jake:This isn't a select feature, again. Like, you can use this everywhere.
  938. Jake:It's Chrome only right now, but it'll
  939. Jake:come to other browsers next year, I guess,
  940. Jake:maybe, hopefully.
  941. Jake:Who knows? Oh, okay, so
  942. Jake:what about the opposite side of the animation?
  943. Jake:So, animating out.
  944. Surma:Well, it's like you said, when a new element appears in the DOM, it's CS animation start
  945. Jake:And this is always the harder one,
  946. Jake:because,
  947. Jake:yeah, because of displaying none,
  948. Jake:and it being removed from the top layer
  949. Jake:immediately.
  950. Surma:playing.
  951. Surma:And so you can just basically put a fade in animation on an element.
  952. Surma:And once attached to the DOM, you know, animation will play.
  953. Surma:You can set it.
  954. Surma:It's a repeat to one.
  955. Surma:You can listen to the transition or animation and events and just go about your life.
  956. Jake:Exactly.
  957. Surma:But when you remove a DOM element from the tree, it's gone.
  958. Surma:There's no way to intercept that and keep it on screen to fade it out or anything like
  959. Surma:that.
  960. Jake:There's a solution for it as well.
  961. Jake:I mean, one way is view transitions,
  962. Jake:but if you're just
  963. Jake:making something display none and removing
  964. Jake:it from the top layer, there's another way of handling it.
  965. Jake:You can set a CSS animation
  966. Jake:or transition on the display property,
  967. Jake:which delays
  968. Surma:Wait, I thought discrete values could already transition, they just flip at 50%.
  969. Jake:it applying
  970. Jake:if you're animating out.
  971. Jake:So,
  972. Jake:you need to opt into this.
  973. Jake:It just works with animations,
  974. Jake:but with transitions, you need to use
  975. Jake:transition-behavior
  976. Jake:allow-discrete,
  977. Jake:which allows discrete values to transition.
  978. Jake:It's on all discrete values, but...
  979. Jake:No, that's how it works with animations.
  980. Surma:Oh.
  981. Jake:They don't work with transitions
  982. Jake:until you flip this bit,
  983. Surma:Flip a bit.
  984. Jake:and then it's fine.
  985. Jake:But when something is transitioning
  986. Jake:to display none, it converts
  987. Jake:to display none at the very end,
  988. Jake:but it becomes inert during
  989. Jake:the whole period.
  990. Surma:Very good.
  991. Jake:So that means that screen readers,
  992. Jake:keyboard, mouse, it's gone.
  993. Jake:It avoids the accessibility
  994. Jake:issues, and it means you can't
  995. Jake:double-click on a button inside that thing
  996. Jake:that you've told to go away.
  997. Jake:This is probably the last feature
  998. Jake:I got in to Web Standards
  999. Surma:I mean, that's a really good improvement.
  1000. Jake:before I left Google. I had to get
  1001. Jake:testimony from a bunch of framework
  1002. Jake:developers to say that this is important
  1003. Jake:and this would be a
  1004. Jake:foot gun if it's not done.
  1005. Jake:So that is one of the features
  1006. Jake:that has landed.
  1007. Surma:The only thing I wish there was that there's some way to say, like, if a DOM element gets
  1008. Surma:removed, remove it from the JavaScript facing API, but keep it around until the animation
  1009. Surma:is done.
  1010. Surma:Especially if a framework just removes an element, then the just just to see as animation
  1011. Jake:You're pretending like I never created
  1012. Jake:view transitions, Sama, actually?
  1013. Surma:can play.
  1014. Jake:But that was
  1015. Surma:But those are just for transitioning views, isn't it?
  1016. Jake:one of the problems we aimed to solve there.
  1017. Jake:It's like, how can you animate the thing
  1018. Jake:that isn't there anymore?
  1019. Jake:The solution to that was to use
  1020. Jake:screenshots of the old thing.
  1021. Surma:Here's my confession.
  1022. Surma:I have not used view transitions.
  1023. Jake:Mate.
  1024. Surma:I've not written any.
  1025. Jake:Mate.
  1026. Jake:Cut steep.
  1027. Surma:I think I think I think you're breaking up with me.
  1028. Jake:I think I am.
  1029. Jake:No, I
  1030. Jake:forgive you. I think
  1031. Jake:my confession is now that we've got
  1032. Jake:cross-document view
  1033. Jake:transitions, I kept meaning to add them to
  1034. Jake:my blog and stuff, and I just
  1035. Jake:haven't found the time.
  1036. Jake:Whatever.
  1037. Jake:Okay. Back to the problem.
  1038. Jake:We haven't solved the full problem, because we've still
  1039. Surma:Wait, did I get the problem right?
  1040. Jake:got that issue of it disappearing off the top layer.
  1041. Jake:So, the solution to that
  1042. Jake:is to set a transition on this
  1043. Jake:new CSS property called
  1044. Jake:overlay, and that
  1045. Jake:is a way of kind of delaying
  1046. Jake:it disappearing from the
  1047. Jake:top layer. It kind of pretends
  1048. Jake:like overlay has a value
  1049. Jake:of top layer, but you're not allowed to set this yourself.
  1050. Surma:The ring is like when I'm closing my custom select, it just poofs goes away.
  1051. Surma:And we obviously want to have an opportunity to make it smoothly go away to the developers
  1052. Jake:So,
  1053. Jake:you need to keep
  1054. Surma:liking.
  1055. Jake:display around
  1056. Jake:for longer, but you also need to keep it
  1057. Jake:in the top layer for longer. This problem
  1058. Jake:also exists with the dialog
  1059. Jake:element. So, yes, it's kind of pretend
  1060. Jake:property that lets you
  1061. Jake:set something into the top layer, except you're not
  1062. Jake:allowed to set it in the top layer, but
  1063. Jake:you can put it in a transition which
  1064. Jake:keeps this user agent set value
  1065. Jake:top layer
  1066. Jake:around for a bit longer.
  1067. Jake:It's a bit hacky,
  1068. Surma:Ah, it feels odd, but I guess it solves the problem.
  1069. Jake:but it does work.
  1070. Surma:But it's limited to things in the topic.
  1071. Surma:I can't just use the same thing on elements anywhere else on the page.
  1072. Jake:So, with this display property,
  1073. Jake:you can use that on any element.
  1074. Jake:Yeah, that works on anything, and it's in Chrome and
  1075. Jake:Safari now. But this
  1076. Jake:extra one that does the top layer
  1077. Jake:thing, that's Chrome only
  1078. Jake:right now. And yes, that's only really useful
  1079. Jake:for
  1080. Jake:this select element thing.
  1081. Jake:It's useful for popovers, and it's useful for
  1082. Surma:Right.
  1083. Jake:dialog.
  1084. Surma:OK, that makes sense.
  1085. Jake:Final bit. I sort of
  1086. Jake:described it as like we're doing an animation in,
  1087. Jake:but we're having to use transition
  1088. Jake:to make something transition out.
  1089. Jake:And the reason for that is because
  1090. Jake:if you want something to animate just when it appears,
  1091. Jake:that's not a transition because it's in that
  1092. Surma:Mm hmm.
  1093. Jake:state already, whereas animations do let
  1094. Jake:you do that. Something appears, do your animation.
  1095. Jake:But they've also added a way to make this work
  1096. Jake:for CSS transitions. And that's
  1097. Jake:of benefit because it means that
  1098. Jake:if the transition in is interrupted,
  1099. Jake:it can skip
  1100. Surma:Mm hmm.
  1101. Jake:some of the transition out. It can start
  1102. Jake:it halfway through or whatever to make
  1103. Jake:a smooth transition. That's one of the
  1104. Surma:Mm hmm.
  1105. Jake:nice benefits of CSS transitions.
  1106. Jake:So they added
  1107. Jake:at starting style, which is a block
  1108. Jake:which lets you,
  1109. Jake:for a selector,
  1110. Jake:say, pretend
  1111. Jake:that it had these styles
  1112. Surma:Mm hmm.
  1113. Jake:before it was created.
  1114. Jake:And so if that has
  1115. Jake:a transition applied to it,
  1116. Surma:Yeah.
  1117. Jake:when the thing appears, it's going to transition from those
  1118. Jake:starting styles to its actual styles.
  1119. Surma:I feel like I love the problem.
  1120. Jake:...
  1121. Jake:...
  1122. Surma:I love that they made a solution. I'm not sure I love this specific solution syntactically.
  1123. Jake:...
  1124. Jake:...
  1125. Surma:But, you know what? In the end, like, I don't have a better solution at hand.
  1126. Jake:...
  1127. Jake:...
  1128. Surma:So, and again, I can use this on any element, right? Like, I can define a
  1129. Jake:...
  1130. Jake:...
  1131. Surma:transition now that plays when I add an element to the tree.
  1132. Jake:...
  1133. Jake:...
  1134. Surma:Not just an animation. That's really cool.
  1135. Jake:Yeah, I agree that
  1136. Jake:so much new syntax is being chucked
  1137. Jake:at CSS. It's kind of growing
  1138. Jake:faster syntactically than
  1139. Jake:JavaScript, it feels like.
  1140. Surma:Mm hmm.
  1141. Jake:Yeah, and it's difficult to keep up with.
  1142. Jake:But yeah, it's a solution to the problem.
  1143. Jake:And yeah, you can use it everywhere, but it is
  1144. Jake:useful for select.
  1145. Jake:So that's it, really.
  1146. Jake:We're almost in a position to create these
  1147. Jake:custom select things. People should play with it
  1148. Jake:and give feedback.
  1149. Surma:Yeah, I'm genuinely quite excited to look at some, I'm sure you will have
  1150. Jake:...
  1151. Jake:...
  1152. Surma:some demos to link to that I can look at in Chrome Canary or something.
  1153. Jake:...
  1154. Jake:Yes, I'll link to all of that.
  1155. Surma:Because I want to dig into that code and get a bit familiar with all
  1156. Jake:...
  1157. Jake:...
  1158. Surma:the individual primitives. Because what I do think is really, really nice that they didn't
  1159. Jake:...
  1160. Jake:...
  1161. Surma:just, here is a stylable select. But they were like, what is
  1162. Jake:...
  1163. Jake:...
  1164. Surma:missing across the platform that we can then compose to
  1165. Jake:...
  1166. Jake:...
  1167. Surma:yield a stylable select element. And yeah, that deserves applause.
  1168. Jake:...
  1169. Jake:...
  1170. Surma:That's really cool that they went about it this way.
  1171. Jake:Exactly, yeah. It's ten general features,
  1172. Jake:right? We've got popovers, buttons that
  1173. Jake:can activate
  1174. Jake:popovers, and they're also
  1175. Jake:working on general activation,
  1176. Jake:like general declarative,
  1177. Jake:you know, click this button, it makes this other thing do a thing,
  1178. Surma:Thank you.
  1179. Jake:whatever. CSS anchor
  1180. Jake:positioning, the open and close pseudo-elements,
  1181. Jake:transitioning, animating
  1182. Jake:to keyword sizes, like height-auto,
  1183. Jake:calculations involving
  1184. Jake:those keyword sizes,
  1185. Jake:transitioning to discrete values,
  1186. Jake:like display-none,
  1187. Jake:that kind of thing, animating
  1188. Jake:display with auto-inert, animating the
  1189. Jake:overlay for the top-layer thing,
  1190. Jake:and the starting style. That's ten features
  1191. Jake:that are kind of all part of
  1192. Jake:making custom selects work,
  1193. Jake:but you can use them elsewhere.
  1194. Surma:It's a pretty big flex for standards land.
  1195. Jake:...
  1196. Jake:... Yeah.
  1197. Jake:It feels like the right way, right?
  1198. Jake:Rather than just, as you said,
  1199. Jake:creating a general select thing that has
  1200. Jake:all of this magic in it, it's like, no.
  1201. Jake:Most of the magic can be explained by
  1202. Jake:other features.
  1203. Surma:Yeah, no, that's brilliant. That's really good.
  1204. Jake:...
  1205. Jake:That's all I've got. That's it.
  1206. Jake:That's it. That's the content.
  1207. Surma:I mean, you say like that wasn't a lot. I feel like you have explained ten features.
  1208. Jake:...
  1209. Jake:...
  1210. Surma:So I'm gonna, I'm gonna have to sit down and digest.
  1211. Jake:...
  1212. Jake:Well, there you go. Oh, thanks, mate.
  1213. Jake:Yeah. Shall we all have a
  1214. Jake:lie down?
  1215. Surma:Yeah, let's let's have a lie down.
  1216. Jake:All right, then.
  1217. Jake:Okay. Well, there's nothing
  1218. Jake:else to say other than
  1219. Jake:happy next time. Bye!
  1220. Surma:Happy next time.
  1221. Jake:...
  1222. Jake:...
  1223. Jake:...
  1224. Jake:...
  1225. Jake:...
  1226. Jake:...