Skip to content

Once <progress> value attribute has been set, it will never be removed. #4487

@jacobalbano

Description

@jacobalbano
  • Check if updating to the latest Preact version resolves the issue

Describe the bug
Once <progress> value attribute has been set, it will never be removed.

On this element, the absence of a value attribute has significance:

If there is no value attribute, the progress bar is indeterminate; this indicates that an activity is ongoing with no indication of how long it is expected to take.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress

Currently I'm unable to remove the attribute without resorting to direct DOM manipulation.

To Reproduce
Run the following code at https://preactjs.com/repl

import { render, Component } from 'preact';

class ProgressDemo extends Component {
	constructor() {
		super();
		this.state = { loading: true };
	}

	render() {
		const { loading } = this.state;
		const value = loading ? undefined : 1;
		return (
			<div>
				<div>Progress should {loading || 'not'} be animated.</div>

				<div>
					<progress value={value} />
					<button onClick={() => this.setState({ loading: !loading })}>
						Loading ({String(loading)})
					</>
				</>

				<div><code>state.loading</code> is {String(loading)}</div>
				<div><code>progress.loading</code> is being set to {String(value)}</div>
			</>
		);
	}
}

render(<ProgressDemo />, document.getElementById('app'));

Expected behavior

  • Progress bar is initially rendered as <progress>, with no value attribute, so it animates in an indeterminate state
  • Clicking the button sets loading to false, which results in the html <progress value="1">. Animation stops.
  • Clicking the button again sets loading to true, which results in the same initial html, <progress> with no value attribute. Animation resumes.

Actual behavior

  • Once value has been set once, attempting to set it to a falsey value will will have no effect; the attribute will retain its previous value and will not be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions