Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] How to prevent mousewheel in input of type number? #7960

Closed
barbalex opened this issue Aug 30, 2017 · 29 comments
Closed

[TextField] How to prevent mousewheel in input of type number? #7960

barbalex opened this issue Aug 30, 2017 · 29 comments
Labels
component: number field This is the name of the generic UI component, not the React module! component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@barbalex
Copy link

Problem description

Scrolling in a number field changes the values. In all the applications I have built so far people have asked me to prevent this behaviour because it sometimes causes corrupted data.

See also https://stackoverflow.com/questions/9712295/disable-scrolling-on-input-type-number/38589039#38589039

Steps to reproduce

Build a TextField of type number. Set focus into it. Scroll with your mousewheel.

Versions

This happens in all browsers in input elements, as far as I know.

Workaround

I have tried this:

document.addEventListener('mousewheel', function(event) {
  if (window.document.activeElement.type === 'number') {
    event.preventDefault()
  }
})

But it only seems to work sometimes. No Idea why it only works inconsistently.

Request

Now I see that changing standard behaviour would not be good. But adding this as an option would be very nice.

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 30, 2017

@barbalex I'm not sure to follow. What's preventing you from implementing this behavior? I can't think of anything we are doing to block the behavior. You could try to reproduce the issue on a native <input /> to make sure it's Material UI-related and not React-related.

I'm closing. Feel free to reopen if you can provide a reproduction example. codesandbox.io is a good place to start with.

As a side note, we are bringing a number input: #19154.

@oliviertassinari oliviertassinari added component: text field This is the name of the generic UI component, not the React module! v1 waiting for 👍 Waiting for upvotes labels Aug 30, 2017
@oliviertassinari oliviertassinari removed the waiting for 👍 Waiting for upvotes label Oct 2, 2017
@Tomlgls
Copy link

Tomlgls commented Nov 21, 2018

Hi. It's working with :

<TextField type="number" onWheel={event => { event.preventDefault(); }} />

Hope it will helps.

@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Nov 21, 2018
@oliviertassinari oliviertassinari changed the title add option to prevent mousewheel event in textfield of type number [TextField] How to prevent mousewheel in input of type number Nov 21, 2018
@oliviertassinari oliviertassinari changed the title [TextField] How to prevent mousewheel in input of type number [TextField] How to prevent mousewheel in input of type number? Nov 21, 2018
@barbalex
Copy link
Author

barbalex commented Jun 1, 2019

Both my general workaround and @Tomlgls do not seem to work any more in Chrome. When you implement them an error appears:

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312

Linking to this page: https://www.chromestatus.com/features/6662647093133312

I have absolutely no idea why this would happen when you specifically add an onWheel event listener directly on the Input. But that is what happens.

Just to explain why this is important:

When users enter a value in a number field and then scroll the window, they inadvertently change the value they just have set. This is horrible UX and that is why I keep getting error reports about this "feature" that unfortunately is standard behavior. Also: The window does not scroll (but that is a lesser concern).

It obviously has nothing to do with material-ui but fact is that I have to somehow prevent this when using material-ui.

The issue is visible on the material-ui demo page. I have also prepared a demo that also shows that the onWheel does not prevent it from happening any more: https://codesandbox.io/s/material-demo-wdgpg?fontsize=14.

Instructions to reproduce the basic effect:

  1. visit https://codesandbox.io/s/material-demo-wdgpg?fontsize=14 using chrome
  2. click into first field. Enter a number
  3. without having moved your mouse scroll as if you were in a long form and wanted to scroll down further
  4. watch the number you just entered change

Instructions to reproduce that an onWheel event handler cannot prevent this:

  1. visit https://codesandbox.io/s/material-demo-wdgpg?fontsize=14 using chrome
  2. click into second field (which has the onWheel event handler implemented). Enter a number
  3. without having moved your mouse scroll as if you were in a long form and wanted to scroll down further
  4. watch the console

@joshwooding
Copy link
Member

joshwooding commented Jun 1, 2019

@barbalex I will confess I haven't looked at this problem in depth, but you can get around the passive event error by attaching it to a TextField using addEventListener e.g. https://codesandbox.io/s/n3scr

import React from "react";
import clsx from "clsx";
import { makeStyles } from "@material-ui/core/styles";
import MenuItem from "@material-ui/core/MenuItem";
import TextField from "@material-ui/core/TextField";

const useStyles = makeStyles(theme => ({
  container: {
    display: "flex",
    flexWrap: "wrap"
  },
  textField: {
    marginLeft: theme.spacing(1),
    marginRight: theme.spacing(1),
    width: 200
  },
  dense: {
    marginTop: 19
  },
  menu: {
    width: 200
  }
}));

const currencies = [
  {
    value: "USD",
    label: "$"
  },
  {
    value: "EUR",
    label: "€"
  },
  {
    value: "BTC",
    label: "฿"
  },
  {
    value: "JPY",
    label: "¥"
  }
];

function TextFields() {
  const classes = useStyles();
  const [values, setValues] = React.useState({
    name: "Cat in the Hat",
    age: "",
    multiline: "Controlled",
    currency: "EUR"
  });
  const textFieldRef = React.useRef(null);

  React.useEffect(() => {
    const handleWheel = e => e.preventDefault();
    textFieldRef.current.addEventListener("wheel", handleWheel);

    return () => {
      textFieldRef.current.removeEventListener("wheel", handleWheel);
    };
  }, []);

  const handleChange = name => event => {
    setValues({ ...values, [name]: event.target.value });
  };

  return (
    <form className={classes.container} noValidate autoComplete="off">
      <TextField
        id="standard-number"
        label="Regular Number field"
        value={values.age}
        onChange={handleChange("age")}
        type="number"
        className={classes.textField}
        InputLabelProps={{
          shrink: true
        }}
        margin="normal"
      />
      <TextField
        id="standard-number"
        label="Number Field with onWheel handler. Watch the console"
        value={values.age}
        onChange={handleChange("age")}
        type="number"
        className={classes.textField}
        InputLabelProps={{
          shrink: true
        }}
        margin="normal"
        ref={textFieldRef}
      />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
      <p>text to create a long form you will have to scroll</p>
      <br />
    </form>
  );
}

export default TextFields;

@barbalex
Copy link
Author

barbalex commented Jun 6, 2019

nice one @joshwooding, thanks!

@peterbartos
Copy link
Contributor

peterbartos commented Jun 18, 2019

An easy fix also working for new Chrome is:

<TextField type="number" onWheel={ event => event.currentTarget.blur() }} />

@barbalex
Copy link
Author

barbalex commented Jul 9, 2019

@peterbartos
Unfortunately your solution also produces this error: [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

Only working solution so far seems to be @joshwooding #7960 (comment)

@peterbartos
Copy link
Contributor

@barbalex are you sure you tested exactly the blur() approach? I'm not calling there preventDefault(). Blur itself helps to avoid changing input number by scroll.

@barbalex
Copy link
Author

barbalex commented Jul 10, 2019

@peterbartos yeah, it sounds kind of weird that the error mentions preventDefault when onWheel only blured the current target.

Double checking I now see that [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. must have been caused by something else. I probably still had a preventDefault call in the component when testing blur(). Sorry for the negligence :-(

BUT: onWheel={ event => event.currentTarget.blur() } does not prevent the numbers from changing when I scroll while focus is in a number field.

I tested this again by deactivating @joshwooding 's solution and adding yours.

What completely baffles me: This blurs:

  const onKeyDown = e => {
    if (e.key === 'Enter') {
      handleSubmit()
      // show user something happened
      e.currentTarget.blur()
    }
  }

This does not blur:

const onWheel = e => e.currentTarget.blur()

@barbalex
Copy link
Author

Just in case someone lands here looking for a working example, here is my TextField component. It is used with formik:

import React, { useCallback, useEffect, useRef } from 'react'
import Input from '@material-ui/core/Input'
import InputLabel from '@material-ui/core/InputLabel'
import FormControl from '@material-ui/core/FormControl'
import FormHelperText from '@material-ui/core/FormHelperText'
import styled from 'styled-components'
import { observer } from 'mobx-react-lite'

const StyledFormControl = styled(FormControl)`
  padding-bottom: 19px !important;
  > div:before {
    border-bottom-color: rgba(0, 0, 0, 0.1) !important;
  }
`

const MyTextField = ({
  field,
  form,
  label,
  type = 'text',
  multiLine = false,
  disabled = false,
  hintText = '',
  helperText = '',
  required = false,
}) => {
  const { onChange, onBlur, value, name } = field
  const { errors, handleSubmit } = form
  const error = errors[name]

  // only working solution to prevent whell scrolling from changing number values
  // see: https://github.com/mui-org/material-ui/issues/7960#issuecomment-497945204
  const textFieldRef = useRef(null)
  useEffect(() => {
    const handleWheel = e => e.preventDefault()
    textFieldRef.current.addEventListener('wheel', handleWheel)

    return () => {
      textFieldRef.current.removeEventListener('wheel', handleWheel)
    }
  }, [])

  // value should immediately update when pressing Enter
  const onKeyDown = useCallback(e => {
    if (e.key === 'Enter') {
      handleSubmit()
      // show user something happened
      e.currentTarget.blur()
    }
  })

  return (
    <StyledFormControl
      fullWidth
      disabled={disabled}
      error={!!error}
      aria-describedby={`${label}ErrorText`}
    >
      <InputLabel htmlFor={label} shrink required={required}>
        {label}
      </InputLabel>
      <Input
        id={name}
        ref={textFieldRef}
        name={name}
        value={value || ''}
        type={type}
        multiline={multiLine}
        onChange={onChange}
        onBlur={onBlur}
        onKeyDown={onKeyDown}
        placeholder={hintText}
        autoComplete="off"
        autoCorrect="off"
        autoCapitalize="off"
      />
      {!!error && (
        <FormHelperText id={`${label}ErrorText`}>{error}</FormHelperText>
      )}
      {!!helperText && (
        <FormHelperText id={`${label}HelperText`}>{helperText}</FormHelperText>
      )}
    </StyledFormControl>
  )
}

export default observer(MyTextField)

@oliviertassinari
Copy link
Member

A great alternative solution #10582 (comment)

dmitry-brazhenko pushed a commit to plynx-team/plynx that referenced this issue May 27, 2020
khaxis added a commit to plynx-team/plynx that referenced this issue May 29, 2020
* fix bug with search bar in code editor

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* update version

Co-authored-by: Dmitry Brazhenko <[email protected]>
dmitry-brazhenko added a commit to plynx-team/plynx that referenced this issue Jun 2, 2020
* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Jun 8, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Jun 14, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Jun 14, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

* fix bug with cache: legacy from 0.*

* update version

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Jul 11, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

* fix bug with cache: legacy from 0.*

* update version

* Add File operation (#62)

* initial file dialog

* files support in executors

* using single endpoint config parameter

* add static support to node view

* fix lint

* add file preview

* cleanup

* update version

* Fix make dev (#64)

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerignore (#66)

* Fix make dev

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerfile to .dockerignore to allow docker to run with data file

* update version

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: houjo <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Sep 8, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

* fix bug with cache: legacy from 0.*

* update version

* Add File operation (#62)

* initial file dialog

* files support in executors

* using single endpoint config parameter

* add static support to node view

* fix lint

* add file preview

* cleanup

* update version

* Fix make dev (#64)

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerignore (#66)

* Fix make dev

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerfile to .dockerignore to allow docker to run with data file

* update version

* Dev (#71)

* added cogs

* Succefully integrated setting cookies and /setting

* made it so the state was hosted in app

* added node Display setting

* created endpoint to connect configs to settings

* finished endpoint and handeling

* Turned Setting page into a modal

* Added settings as modal added endpoint to access

* Revert "Dev (#71)" (#72)

This reverts commit f1dc8ea.

* User Profile page (#74)

* User Settings / User View page
* IAM Policies for users: IS_ADMIN, CAN_VIEW_OPERATIONS etc.
* User can change password, display name and operation view mode

* Added rudementary registration (#76) (#80)

* Added rudementary registration (#76)

* Added rudementary registration

* intermitent changes

* interstage

* Fix for pr

Co-authored-by: Ivan <[email protected]>

* rm unused file

* integrate sign up page

Co-authored-by: houjo <[email protected]>

* rm dashboard

* rm header

* resolve caps problem in path

* adapt error page for other than 404 errors

* rename logout to sign out

* fix vulnerability

* post node iam policies

* use dark skin in table preview

* hide cancel button unless it's a run

* show the user who runs an operation rather than the author

* fix a bug with assigning the author

* finally hide cancel button in templates

* use original_node_id in runs

* support can_view* roles

* update version

* rm debug logging

* lint fix

* raise instead of assert

* rm unnecessary logs

* intermediate changes

* show tour when start plynx for the first time

* update version

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: houjo <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Sep 8, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

* fix bug with cache: legacy from 0.*

* update version

* Add File operation (#62)

* initial file dialog

* files support in executors

* using single endpoint config parameter

* add static support to node view

* fix lint

* add file preview

* cleanup

* update version

* Fix make dev (#64)

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerignore (#66)

* Fix make dev

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerfile to .dockerignore to allow docker to run with data file

* update version

* Dev (#71)

* added cogs

* Succefully integrated setting cookies and /setting

* made it so the state was hosted in app

* added node Display setting

* created endpoint to connect configs to settings

* finished endpoint and handeling

* Turned Setting page into a modal

* Added settings as modal added endpoint to access

* Revert "Dev (#71)" (#72)

This reverts commit f1dc8ea.

* User Profile page (#74)

* User Settings / User View page
* IAM Policies for users: IS_ADMIN, CAN_VIEW_OPERATIONS etc.
* User can change password, display name and operation view mode

* Added rudementary registration (#76) (#80)

* Added rudementary registration (#76)

* Added rudementary registration

* intermitent changes

* interstage

* Fix for pr

Co-authored-by: Ivan <[email protected]>

* rm unused file

* integrate sign up page

Co-authored-by: houjo <[email protected]>

* rm dashboard

* rm header

* resolve caps problem in path

* adapt error page for other than 404 errors

* rename logout to sign out

* fix vulnerability

* post node iam policies

* use dark skin in table preview

* hide cancel button unless it's a run

* show the user who runs an operation rather than the author

* fix a bug with assigning the author

* finally hide cancel button in templates

* use original_node_id in runs

* support can_view* roles

* update version

* rm debug logging

* lint fix

* raise instead of assert

* rm unnecessary logs

* intermediate changes

* show tour when start plynx for the first time

* update version

* hotfix: demo user settings

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: houjo <[email protected]>
khaxis added a commit to plynx-team/plynx that referenced this issue Sep 9, 2020
* build fix: add dateformat

* fix style in deprecate dialog

* Update date format (#52)

* Support of float input type

* Disabled autocomplete in input fields

* Removed annoying Input spinners

https://codepen.io/ahastudio/pen/eVovMv

* Prevents change of numbers with mouse wheel

mui/material-ui#7960

* Removed number scrolling on keyboard arrow

* Backend bug fix

* Prettified "cross-remove" button

* Added \n to newfile

* Updated displayed datetime format

* Revert "Updated displayed datetime format"

This reverts commit a432546.

* first version of correct datetime in operation editor

* Updated and used function utcTimeToLocal

* Fixed bug updated/created

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Ivan Khomyakov <[email protected]>

* rm unnecessary import; add output to filename var in local executor

* give more space for output name

* Kubernetes operation (#55)

* +k8s operation prototype

* add request/limit memory

* fix k8s operator

* flake8

* add logging line

* use template config instead of versioning it

* update version

* rm config from standard docker image

* add k8s icon

* add lock in worker update to address #57

* mount config in dev environment

* cache the results of cacheable operations

* add gpu support to k8s operation

* use new kubectl interface

* update to beta

* update version

* fix circleci

* fix bug with cache: legacy from 0.*

* update version

* Add File operation (#62)

* initial file dialog

* files support in executors

* using single endpoint config parameter

* add static support to node view

* fix lint

* add file preview

* cleanup

* update version

* Fix make dev (#64)

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerignore (#66)

* Fix make dev

- add install to docker-compose-dev.yml by installing dependencies before npm start
- add .dockerignore to run make dev after data file is made

* Rename .dockerfile to .dockerignore to allow docker to run with data file

* update version

* Dev (#71)

* added cogs

* Succefully integrated setting cookies and /setting

* made it so the state was hosted in app

* added node Display setting

* created endpoint to connect configs to settings

* finished endpoint and handeling

* Turned Setting page into a modal

* Added settings as modal added endpoint to access

* Revert "Dev (#71)" (#72)

This reverts commit f1dc8ea.

* User Profile page (#74)

* User Settings / User View page
* IAM Policies for users: IS_ADMIN, CAN_VIEW_OPERATIONS etc.
* User can change password, display name and operation view mode

* Added rudementary registration (#76) (#80)

* Added rudementary registration (#76)

* Added rudementary registration

* intermitent changes

* interstage

* Fix for pr

Co-authored-by: Ivan <[email protected]>

* rm unused file

* integrate sign up page

Co-authored-by: houjo <[email protected]>

* rm dashboard

* rm header

* resolve caps problem in path

* adapt error page for other than 404 errors

* rename logout to sign out

* fix vulnerability

* post node iam policies

* use dark skin in table preview

* hide cancel button unless it's a run

* show the user who runs an operation rather than the author

* fix a bug with assigning the author

* finally hide cancel button in templates

* use original_node_id in runs

* support can_view* roles

* update version

* rm debug logging

* lint fix

* raise instead of assert

* rm unnecessary logs

* intermediate changes

* show tour when start plynx for the first time

* update version

* hotfix: demo user settings

* rm unused elements from config; add iam policies

* fix bug when users have no settings legacy

* update version

Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: Dmitry Brazhenko <[email protected]>
Co-authored-by: houjo <[email protected]>
@ankur5984
Copy link

Hi. It's working with :

<TextField type="number" onWheel={event => { event.preventDefault(); }} />

Hope it will helps.

thanks .

@yakubova92
Copy link

yakubova92 commented Jan 14, 2021

onWheel={event => event.target.blur()} works, using onWheel={event => event.currentTarget.blur()} does not work

@Lambtsa
Copy link

Lambtsa commented Apr 29, 2021

An easy fix also working for new Chrome is:
<TextField type="number" onWheel={ event => event.currentTarget.blur() }} />

That is super nice solution!! If a user is scrolling they are usually not wanting to focus on the input too :)

@1337-ishaan
Copy link

Thanks @yakubova92

@patipan-off
Copy link

onWheel={(event) => event.currentTarget.querySelector('input')?.blur()}

@solafidei
Copy link

onWheel={(event) => event.currentTarget.querySelector('input')?.blur()}

I can confirm this worked. I tried both currentTarget.blur() and target.blur().

currentTarget.blur() didn't do anything.
target.blur() gave me an error -> Property 'blur' does not exist on type 'EventTarget'.ts(2339)

Just some more information for a future person.
I am using:
ReactTS 17.0.20
MUI 5.1.1

@dennis-gonzales
Copy link

onWheel={event => event.target.blur()} works, using onWheel={event => event.currentTarget.blur()} does not work

Works for me, thanks.
A little bit of modification for typescript

onWheel={e => e.target instanceof HTMLElement && e.target.blur()}

@kerenren
Copy link

I am using
thus I need to pass the onWheel event handler as bellow

		<OutlinedInput 
                    {...otherProps}
                     inputProps={{ onWheel: (e) => e.target.blur() }} />

@s-sajib
Copy link

s-sajib commented Mar 4, 2023

<TextField type="number" onWheel={ event => event.target.blur() } />

This does the job for me

@alkemyhossain
Copy link

This one works for me though it gave an warning in my IDE but works

onWheel={event => { event.target.blur()}}

@Reda-ELOUAHABI
Copy link

onWheel={event => event.target.blur()} works, using onWheel={event => event.currentTarget.blur()} does not work

Works for me, thanks. A little bit of modification for typescript

onWheel={e => e.target instanceof HTMLElement && e.target.blur()}

the best solution.
detaching the onwheel evenet also works , with the useeffect and the ref attribute, but I prefer this simple/short solution.

@oliviertassinari oliviertassinari added the component: number field This is the name of the generic UI component, not the React module! label Aug 16, 2023
@majdajroudi
Copy link

onWheel={event => event.target.blur()} works, using onWheel={event => event.currentTarget.blur()} does not work

Works for me, thanks. A little bit of modification for typescript

onWheel={e => e.target instanceof HTMLElement && e.target.blur()}

For some reason even the ref solution did not work for me. This one worked perfectly

@jeff-r-koyaltech
Copy link

I saw a solution for this based on jQuery that I really liked, because it's careful to only listen to (and block) onWheel events while the control is focused. So I ported the concept over to React Js - MUI framework's TextField. Here's a git gist:
https://gist.github.com/jeff-r-koyaltech/786b4b31e632398ddc4dba948081c266

Here's the jQuery solution that I borrowed from:
https://stackoverflow.com/a/20838527

Here's some sample code:

import { TextField } from '@mui/material';
import { useRef } from 'react';

export default function TextFieldExt(props) {
  const { type } = props;
  const noStupidWheelScroll = type === 'number';
  const thisTextField = useRef(null);
  const noOnWheelFn = (wheelEv) => {
    wheelEv.preventDefault();
  };
  const wheelScrollOpts = noStupidWheelScroll
    ? {
        onFocus: () => {
          thisTextField.current.addEventListener('mousewheel', noOnWheelFn);
        },
        onBlur: () => {
          thisTextField.current.removeEventListener('mousewheel', noOnWheelFn);
        },
      }
    : {};
  return <TextField ref={thisTextField} {...wheelScrollOpts} {...props} />;
}

And a sample:

<TextFieldExt
  min="0"
  type="number"
  label="Budget Amount"
  name="BudgetAmount"
  onChange={(e) => {
    // ... typical MUI onChange event
  }}
  value={prop.defaultAmount || 0}
/>

@jayeshchoudhary
Copy link

This worked for me in mui v5

<TextField
    type="number"
    onFocus={(e) =>
        e.target.addEventListener(
            "wheel",
            (e) => e.preventDefault(),
            { passive: false }
        )
    }
/>

@RishabaPriyanCMW
Copy link

RishabaPriyanCMW commented Feb 9, 2024

onWheel={e => e.target instanceof HTMLElement && e.target.blur()}

I was using React Hook Forms libraries register method with Mantine
<TextInput type="number" {...register(name)} onWheel={(e) => e.target instanceof HTMLElement && e.target.blur()} />

this enabled me to successfully prevent the onScroll events

@niralivasoya
Copy link

This solution worked for me:

<input
    //...some input properties...//
    type="number"
    onFocus={(e) => e.target.addEventListener("wheel", function (e) { e.preventDefault() }, { passive: false })}
/>

@Turtle-Hwan
Copy link

Thanks for solutions :)
This is worked for me at mui v5 TextField in "react-hook-form" Controller!!
and then I can prevent scroll event on input!!!

<TextField
  ...
  onWheel={e =>
    e.target instanceof HTMLElement && e.target.blur()
  }
/>

@armanrozika
Copy link

onWheel={(event) => event.currentTarget.querySelector('input')?.blur()}

sweet!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: number field This is the name of the generic UI component, not the React module! component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests