Post

So, today I built `<calc-input>`. It’s a custom input element that accepts mathematical formulas — such as 2 + 3 or (2 + 3) * 4 — and automatically toggles between showing the formula on focus and the calculated result on blur. → brm.us/calc-input

Bramus@bram.us

Oh no. I managed to nerd snipe myself into Yet Another Side Project™ … again. Noooooo. #TooManyIdeas

Does it act differently if the user puts an equals sign at the start or end of the formula?

0 reposts0 likes

No. The input does not accept the = sign. The whole expression you enter is evaluated.

My initial expectation was that = at the start would opt into evaluation, whereas = at the end would either replace the formula by its result or work as a comparison operator.

The opt-in is using the component. If you don’t want the result to be evaluated, use a regular text (or number) input.