Skip to content

Conversation

tanhengyeow
Copy link
Contributor

@tanhengyeow tanhengyeow commented Nov 9, 2018

WHY are these changes introduced?

Resolves #420

WHAT is this pull request doing?

Support press and hold to increment/decrement value in Spinner of the numeric TextField.

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {Page, TextField} from '@shopify/polaris';

interface State {}

export default class Playground extends React.Component<never, State> {
  state = {
    value: '1',
  };

  handleChange = (value) => {
    this.setState({value});
  };

  render() {
    return (
      <Page title="Playground">
        {/* Add the code you want to test here */}
        <TextField
          label="Quantity"
          type="number"
          value={this.state.value}
          onChange={this.handleChange}
        />
      </Page>
    );
  }
}

Copy link

@danrosenthal danrosenthal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanhengyeow thanks so much for the contribution! On first glance, this is looking like a good step in the right direction. Can you add some tests to this change to cover all new code paths, and in particular all new props added to Spinner?


@autobind
private handleButtonPress(onChange: Function) {
this.buttonPressTimer = setInterval(onChange, 200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

200 might be a bit long and I think we should consider adding a setTimeout first. That way when clicking and holding, there is an initial delay of maybe 500 then the number quickly increments maybe at an interval of 100. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.buttonPressTimer = setInterval(onChange, 200);
let interval = 200;
const onChangeInterval = () => {
if (interval > 50) {
interval -= 10;
} else {
interval = 50;
}
onChange();
this.buttonPressTimer = window.setTimeout(onChangeInterval, interval);
};
this.buttonPressTimer = window.setTimeout(onChangeInterval, interval);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this will cause the increment to gradually speed up, with an initial delay of 200ms.

number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ I like this suggestion of gradually increasing the speed. Overall, this looks great!

Copy link
Contributor

@tmlayton tmlayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good! As @danrosenthal mentioned, this could use tests though.

@dpersing
Copy link

Hi @tanhengyeow! Are you able to provide any updates around tests? Thanks!

@tanhengyeow
Copy link
Contributor Author

Hey everyone, thanks for the review 😄

The suggestion sounds great and I'll look into adding tests :) I'm having exams now so I can only get back to this during December, hope that's fine :D

@danrosenthal
Copy link

I'm having exams now so I can only get back to this during December, hope that's fine

Totally fine. I'll add [WIP] to the title to indicate that this pull request is a work in progress.

@danrosenthal danrosenthal changed the title [TextField: Spinner] Support press and hold to increment/decrement value [WIP] [TextField: Spinner] Support press and hold to increment/decrement value Nov 21, 2018
@tmlayton tmlayton force-pushed the spinner-press-and-hold-420 branch from 82d4eae to d2653e7 Compare December 8, 2018 20:42
@tmlayton tmlayton changed the title [WIP] [TextField: Spinner] Support press and hold to increment/decrement value [TextField: Spinner] Support press and hold to increment/decrement value Dec 8, 2018
@tmlayton tmlayton dismissed danrosenthal’s stale review December 8, 2018 20:56

All feedback has been addressed

Copy link
Contributor

@tmlayton tmlayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead a tied this one up

@danrosenthal
Copy link

I might be missing something here, but when I tophat, it still just seems to increment and decrement by one digit.

@tmlayton
Copy link
Contributor

When you git log do you see the latest commits? Depending on how you checked this out an upstream might not be set.

@tmlayton tmlayton force-pushed the spinner-press-and-hold-420 branch from bcecf24 to 2215967 Compare December 11, 2018 22:43
@tmlayton tmlayton merged commit 123a54e into Shopify:master Dec 11, 2018
@ghost
Copy link

ghost commented Dec 11, 2018

🎉 Thanks for your contribution to Polaris React!

@danrosenthal danrosenthal temporarily deployed to production December 12, 2018 18:50 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants