Live data from Hacker News

Buttons as Finite Automata

web.stanford.edu

31–40 of 82 posts

Re: Buttons as Finite Automata

#31
post #22

I don’t believe a two-state button is standard HTML.

Not sure what you mean.

I've played with some buttons that struck me as fairly standard and found that they have exactly the semantics implemented here (to fire, you need to press down inside the button area, hold down (leaving the area or not), and release inside the area).

Re: Buttons as Finite Automata

#32
post #31
post #22

I don’t believe a two-state button is standard HTML.

Not sure what you mean. I've played with some buttons that struck me as fairly standard and found that they have exactly the semantics implemented here (to fire, you need to press down inside the button area, hold down (leaving the area or not), and release inside the area).

Buttons can't remember their state. The "fire" circle shouldn't exist, and after you click and release, it should go back to idle up or hover.

This diagram is showing more checkbox behavior rather than button.

Re: Buttons as Finite Automata

#33
This is fun. Now I’m wondering what it looks like as a regular expression.

Here’s my first attempt. (Probably wrong, since I did it by hand.)

  (enter,leave,|press,(enter,leave,)*release,|press,enter,release,leave,|enter,press,leave,(enter,leave,)*release,)*(enter|press,enter,(leave,enter,)*release),press,(leave,enter,)*,release
I’d never really thought about how many different sequences of events can lead to a button activating.

Re: Buttons as Finite Automata

#35
post #15

Its all fun and games until somebody managed to click on your button without hovering first.

I see two ways to do that: 1. keyboard navigation (Enter and space are ignored) 2. hover, then F5 to reload the page (this resets the state, and you get your cursor on the button without a state transition) presses are completely ignored either way

[deleted]

Re: Buttons as Finite Automata

#36
post #15

Its all fun and games until somebody managed to click on your button without hovering first.

I see two ways to do that: 1. keyboard navigation (Enter and space are ignored) 2. hover, then F5 to reload the page (this resets the state, and you get your cursor on the button without a state transition) presses are completely ignored either way

3. $('#ohhai').click()

Re: Buttons as Finite Automata

#37
post #4

Earlier quoted context omitted.

Right click locks you in the "press" state, just so you know.

No repro here (Chrome 99 on Windows): right-clicking the button works the same as left-clicking it (yes, there's my browser's context-menu, but it doesn't seem to interfere with the webpage's logic at my end).

On Chrome on Mac I get the same, and right clicking outside the button makes it stick in the (idle, down) state, hovering makes it move between (hover, pressed) and (idle, down).

Still a crazy cool demo though. Having worked on ui for my hobby games, I always knew it was more complex than just onClick, but this makes me understand it perfectly. I'm probably going to implement a model based on this in my current project.

Re: Buttons as Finite Automata

#38
post #3

This is something I created many, many years back for Stanford’s CS103 course as a lecture demo. Apologies for the lack of mobile support - I’ve always presented this from my laptop. :-)

There appears to be a mistake in the automaton diagram (not operation). The start state is "Idle, Up", and assumes the mouse is presently outside the button. But after doing "Click to Reset", you're already inside the button and so cannot enter it. Thus you should actually, and unfortunately, be in "Idle, Up". The demonstration gets around this by magically jumping to "hover", but this violates the whole educational point of what a start state is.

I know this is nitpicky, and yes, I see that "fire!" is an accepting state, but maybe you could have a special transition from "fire!" to "hover" labelled "reset".

Re: Buttons as Finite Automata

#39
post #3

This is something I created many, many years back for Stanford’s CS103 course as a lecture demo. Apologies for the lack of mobile support - I’ve always presented this from my laptop. :-)

nice! how about something like that for drag/drop? anyone? :)

an oldie but a goodie: https://www.quirksmode.org/blog/archives/2009/09/the_html5_d...

Re: Buttons as Finite Automata

#40
Nice!

It's funny that buttons are the "Hello World" of frontend components, because they're actually feverishly nuanced.

I wrote a proof of concept for one of these, using XState, a few months back.

My use case was a cross platform react native button -- which means there's technically a difference between "pressed" and "hover" -- and there's also a loading state, which required special handling for the a11y state.

https://codesandbox.io/s/fervent-shirley-dgesq?file=/src/Pre...

NOTE: this will open a popup (might have to enable popups) with the visualizer, and it defaults to the a11y machine, but there's a drop down to switch to the main button machine.

Post reply on HN