forked from external-repos/squoosh
Merge branch 'dev' into auto-optimizer-to-ts
This commit is contained in:
@@ -6,10 +6,13 @@ import './custom-els/RangeInput';
|
|||||||
import { linkRef } from 'shared/prerendered-app/util';
|
import { linkRef } from 'shared/prerendered-app/util';
|
||||||
|
|
||||||
interface Props extends preact.JSX.HTMLAttributes {}
|
interface Props extends preact.JSX.HTMLAttributes {}
|
||||||
interface State {}
|
interface State {
|
||||||
|
textFocused: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export default class Range extends Component<Props, State> {
|
export default class Range extends Component<Props, State> {
|
||||||
rangeWc?: RangeInputElement;
|
rangeWc?: RangeInputElement;
|
||||||
|
inputEl?: HTMLInputElement;
|
||||||
|
|
||||||
private onTextInput = (event: Event) => {
|
private onTextInput = (event: Event) => {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
@@ -23,10 +26,19 @@ export default class Range extends Component<Props, State> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
render(props: Props) {
|
private onTextFocus = () => {
|
||||||
|
this.setState({ textFocused: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
private onTextBlur = () => {
|
||||||
|
this.setState({ textFocused: false });
|
||||||
|
};
|
||||||
|
|
||||||
|
render(props: Props, state: State) {
|
||||||
const { children, ...otherProps } = props;
|
const { children, ...otherProps } = props;
|
||||||
|
|
||||||
const { value, min, max, step } = props;
|
const { value, min, max, step } = props;
|
||||||
|
const textValue = state.textFocused ? this.inputEl!.value : value;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label class={style.range}>
|
<label class={style.range}>
|
||||||
@@ -41,13 +53,16 @@ export default class Range extends Component<Props, State> {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
|
ref={linkRef(this, 'inputEl')}
|
||||||
type="number"
|
type="number"
|
||||||
class={style.textInput}
|
class={style.textInput}
|
||||||
value={value}
|
value={textValue}
|
||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
step={step}
|
step={step}
|
||||||
onInput={this.onTextInput}
|
onInput={this.onTextInput}
|
||||||
|
onFocus={this.onTextFocus}
|
||||||
|
onBlur={this.onTextBlur}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user