Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions ethio-intl-documentation/components/GeezNumeralsDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const GeezNumeralsDemo: React.FC = () => {

// Geez numeral conversion function (matching library exactly)
const toEthNumber = (num: number): string => {
// Handle empty/zero state
if (num === 0) {
return "";
}

if (!Number.isInteger(num) || num < 1 || num > 1000000) {
return "Invalid number";
}
Expand Down Expand Up @@ -71,7 +76,15 @@ const GeezNumeralsDemo: React.FC = () => {
}, [inputNumber]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = parseInt(e.target.value);
const inputValue = e.target.value;

// Handle empty input - reset to empty state
if (inputValue === "") {
setInputNumber(0); // Use 0 to represent empty state
return;
}

const value = parseInt(inputValue);
if (!isNaN(value) && value >= 1 && value <= 1000000) {
setInputNumber(value);
}
Comment on lines 88 to 90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic prevents the user from setting the input to 0. If a user types 0, parseInt will correctly parse it, but the condition value >= 1 will evaluate to false, and setInputNumber will not be called. This results in the component's state not being updated, and the input field will revert to its previous value on the next render, which is a confusing user experience.

Since 0 is used to represent the empty state in this component, you should allow setInputNumber(0) to be called when the user types 0. This will make the behavior consistent with clearing the input field.

Suggested change
if (!isNaN(value) && value >= 1 && value <= 1000000) {
setInputNumber(value);
}
if (!isNaN(value) && value >= 0 && value <= 1000000) {
setInputNumber(value);
}

Expand Down Expand Up @@ -105,7 +118,7 @@ const GeezNumeralsDemo: React.FC = () => {
</label>
<input
type="number"
value={inputNumber}
value={inputNumber === 0 ? "" : inputNumber}
onChange={handleInputChange}
min="1"
max="1000000"
Expand Down