React H5鍵盤被遮住問題解決方案. 方按2:

const onWindowSizeChange = (): void => {
// if (document?.activeElement?.tagName == "INPUT") {
// window.setTimeout(function () {
// document?.activeElement?.scrollIntoView(false);
// }, 0);
// }
// if (inputRef.current && inputRef.current.hasFocus()) {
// console.log(inputRef.current);
// window.setTimeout(() => {
// inputRef.current?.scrollIntoView(false);
// }, 0);
// }
};

useEffect(() => {
window.addEventListener("resize", onWindowSizeChange);
return (): void => {
window.removeEventListener("resize", onWindowSizeChange);
};
});

方按2:

const inputRef = useRef<HTMLInputElement | null>(null);

  return (
    <TextField
      {...leftProps}
      size="small"
      className={classes.textField}
      variant="outlined"
      inputRef={inputRef}
      onFocus={(): void => {
        inputRef.current?.scrollIntoView(false);
      }}
      InputProps={{
        ...leftProps.InputProps,
        classes: { "adornedStart": classes.adornedStart, "adornedEnd": classes.adornedEnd },
        ...{ inputComponent: NumberInputFormat as never },
      }}
    />
  );
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章