A select menu that wraps round its own button

I wanted to know if the menu of a <select> could open over its own button, with the button's shape cut out of one corner and the options flowing round the cut the way words flow round a picture. The idea is the Punch-Out Dropdown by Fabio Azevedo (his post). I haven't read his code, and none of it is here. Each control below is one <select> with appearance: base-select. A canvas inside its picker draws the menu and the options, as on /select/.

  1. Nothing pressed yet.

How it works

The picker is placed with CSS anchor positioning so that its corner is 7 px outside the button's corner. It has three @position-try rules, so near the right edge it lines up with the button's right side, and near the bottom of the window it opens upwards. On each frame the layout reads where the button is under the canvas, draws the menu as one path with that corner missing, and breaks the options into lines. A line level with the button is shorter than the others.

The report that suggested this page said to erase the button's rectangle from the picture with destination-out. That makes the hole visible, but the button under it still can't be pressed. Two boxes are in the way, and neither has a pixel there: the picker's own box and the canvas. So the picker has pointer-events: none, its canvas has pointer-events: auto, and the canvas has a clip-path with the same corner missing. I draw an L-shaped path in place of erasing, because the outline and the shadow then follow the cut.

Show the code the layout, the option flow and the page
  1. Three ordinary selects. The options are written in the HTML.
  2. The page script gives each select the picker and logs what was pressed.
  3. Where the picker goes. anchor() on the picker, three fallbacks, and the two pointer-events lines.
  4. The menu's outline. Six points and arcTo().
  5. The option flow. Lines level with the cut are shorter.
  6. The layout. prepare() measures the button and sets the clip-path. place() gives each option its matrix. under() draws the menu.
  7. punchOut(select).
  8. The drawing loop in the picker library that calls the layout.
  9. The page's CSS for the closed select and the options.

Live checks

These open a small test select in a panel at the bottom of the window. They wait for a tap because a picker only opens after one.

Findings