Switch progress type once total amount is determined | progress

プログラミング・Web開発カテゴリを表すパンダのイラスト Programming / Web Development

About this article
This article was created using an automated generation workflow utilizing generative AI. We verified official documentation and fixed educational material implementations to organize operational and technical constraints.

Verification status: 📘 Official information and implementation cross-check. Actual browser verification not performed.

At the start of aggregation, the total number of items is sometimes unknown. We switch the progress field before and after the total count is determined.

Open live demo

Terminology to know first

  • Indeterminate progressis progress where the total amount is unknown.

  • Determinate progressis progress that can indicate both the processed amount and the total amount.

Thinking with a state transition diagram

This diagram is a conceptual illustration of a scenario where the total amount is determined in actual practice. In the educational material, the total amount is fixed to 10, and the display is switched via numerical input. Determinate progress can be represented even when the processed count is 0.

stateDiagram-v2
    state "全体量が未定" as Unknown
    state "0件以上を処理済み" as Known
    state "完了" as Complete
    [*] --> Unknown
    Unknown --> Known: 全体量が10件と判明
    Known --> Complete: 10件処理

Operating the live demo

Try undecided, 0, and 6. Compare the display with the item count.

How to read the results

Undecided and 0/10 result in different states.

Progress can be initialized the moment the item count is determined. Update only the value as the processed item count increases.

Key points of the code

The implementation initially sets max=10 and removes value if undetermined. It sets value when a numeric input is provided.

The implementation can be checked in the implementation code section of the demo screen.

When using it in production

Do not display estimated percentages until the total amount is known.

Observing the difference between undetermined and 0 items

The initial input value is undetermined. Running it should create a progress component and a text field, and the result area is expected to show a message stating that the total amount is currently being investigated. Next, change the generated input field to 0. It should display that 0 items have been processed, distinguishing it from the undetermined state. Furthermore, change it to 6 and 10 to check if the display progresses to show 6 items processed and 10 items processed respectively. Finally, empty the field and verify whether it returns to indeterminate progress.

InputMeaning of the display
Undetermined, empty fieldIndeterminate progress
00 out of 10 items
66 out of 10 items
1010 out of 10 items

This time, actual aggregation processing is not performed. It is a simulation experiment that switches the display based on the values input by the user. The input value judgment part was executed in Node.js, and it was confirmed that undetermined and empty inputs belong to the indeterminate side, while 0, 6, and 10 belong to the determinate side. Actual gauge rendering in HTML has not been verified.

Having no value versus having a value of 0

Progress is an HTML element that indicates the progress state of a task. When both the total amount and the processed amount are known, determinate progress can be expressed using max and value. When progress is underway but the total amount is not yet known, the state where value is omitted can be used. Specifying a value of 0 indicates that the processed amount is 0, not that it is undetermined. Distinguishing between these two makes it easier to communicate whether an investigation is still ongoing or whether the total amount is known but work has not yet started.

The current implementation initially sets max to 10. If the text in the input field is empty or cannot be converted to a finite number, the value attribute is removed using removeAttribute. If a number is received, that value is set to the value attribute. There is no process to detect the total count of 10, nor is the value of max calculated dynamically. Switching to numeric input serves as a proxy for the scenario where the total amount becomes clear. Official documentation also indicates that the value attribute should be removed when reverting to indeterminate progress.

Check the input range.

The implementation checks if the value is finite, but it does not validate business logic conditions such as whether it is an integer or within the range of 0 to 10. The handling of the progress element's value is subject to browser standard range constraints. For example, how the value in the result field behaves when entering 11, a negative number, or a decimal must be observed in actual browsers. The display value stopping at the upper limit and the correctness of the processed count are different things. In actual applications, inconsistent source data should also be validated so that the processed amount does not exceed the total amount.

Some aggregations involve total amounts that change midway. If it is initially estimated at 10 items and becomes 20 items during processing, the progress percentage may drop. Explaining the reason why the total amount changed rather than just showing the percentage makes it less likely for users to mistakenly perceive it as an error. A design that synchronizes the displayed value with the actually completed processing is also required.

Application to Job Status Display

In scenarios where files are loaded and processed, the target item count is checked first, and the number of processed items is reported after the count is finalized. Assigning a definitive percentage, such as 80%, based solely on estimation for tasks where the total amount cannot be grasped misleads user judgment. There is a method to explain what is currently being executed in text and combine it with indeterminate progress. If processing fails or is aborted, display a state distinct from completion.

If the gauge value does not change, check whether input events are occurring and whether the value attribute exists. Also, test separately whether the current state can be understood via screen readers. The published educational material uses a fictional 10 items and does not perform actual file processing or transmission. Consider the processing to correctly acquire the workload and the processing to display progress clearly as separate concerns.

Verification Scope

Target: HTML progress. Executed the same branching as the implementation on Node.js v22.16.0. Undefined and blank are treated as unknown, while 0/6/10 are treated as known. HTMLProgressElement position and rendering were not executed. Browser compatibility, display, accessibility, and Mermaid rendering were not verified.

References

GitHub Sample

Implementation and Experiment Procedure

Document information

Article title
Switch progress type once total amount is determined | progress
Published
Updated
Source
https://papanda925.com/?p=19158&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL