mirror of
https://github.com/kremalicious/asi-calculator.git
synced 2024-12-22 09:23:16 +01:00
auto growing inputs
This commit is contained in:
parent
4850c19417
commit
110744f4ce
@ -1,7 +1,6 @@
|
|||||||
.input {
|
.input {
|
||||||
all: unset;
|
all: unset;
|
||||||
width: 60px;
|
padding: 0 0.75rem;
|
||||||
padding: 0 0.2rem;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-right: 1px solid rgba(var(--foreground-rgb), 0.15);
|
border-right: 1px solid rgba(var(--foreground-rgb), 0.15);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { Dispatch, SetStateAction } from 'react'
|
'use client'
|
||||||
|
|
||||||
|
import { Dispatch, SetStateAction, useRef, useState } from 'react'
|
||||||
import styles from './InputAmount.module.css'
|
import styles from './InputAmount.module.css'
|
||||||
|
|
||||||
export function InputAmount({
|
export function InputAmount({
|
||||||
@ -8,6 +10,16 @@ export function InputAmount({
|
|||||||
amount: number
|
amount: number
|
||||||
setAmount: Dispatch<SetStateAction<number>>
|
setAmount: Dispatch<SetStateAction<number>>
|
||||||
}) {
|
}) {
|
||||||
|
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
|
const { value } = e.target
|
||||||
|
|
||||||
|
if (value === '') {
|
||||||
|
setAmount(0)
|
||||||
|
} else {
|
||||||
|
setAmount(Number(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
className={styles.input}
|
className={styles.input}
|
||||||
@ -15,7 +27,10 @@ export function InputAmount({
|
|||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
pattern="[0-9]*"
|
pattern="[0-9]*"
|
||||||
value={amount}
|
value={amount}
|
||||||
onChange={(e) => setAmount(Number(e.target.value))}
|
onChange={handleChange}
|
||||||
|
style={{
|
||||||
|
width: Math.min(Math.max(amount.toString().length, 2), 50) + 'ch'
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
.select {
|
.select {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
all: unset;
|
all: unset;
|
||||||
padding: 0 0.5rem;
|
padding: 0 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.select:hover:not(.select[disabled]) {
|
.select:hover:not(.select[disabled]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user