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

Adding Event on RangeSelector.Button is not working #79

Closed
mwubgadeashish opened this issue Mar 5, 2018 · 9 comments
Closed

Adding Event on RangeSelector.Button is not working #79

mwubgadeashish opened this issue Mar 5, 2018 · 9 comments

Comments

@mwubgadeashish
Copy link

            ```<RangeSelector selected={1}>
                <RangeSelector.Button count={24} type="hour" onClick={this.handleClick}>P</RangeSelector.Button>
                <RangeSelector.Button count={1} type="day">1d</RangeSelector.Button>
                <RangeSelector.Button count={2} type="day">2d</RangeSelector.Button>
                <RangeSelector.Button count={1} type="week">1w</RangeSelector.Button>
                <RangeSelector.Button count={1} type="month">1m</RangeSelector.Button>
                <RangeSelector.Button type="all">all</RangeSelector.Button>
            </RangeSelector>```

I am trying to add a click event on button and seems its not working. I have also added following line:

// In constructor
this.handleClick = this.handleClick.bind(this);
//added method
handleClick  = (e) => {
        console.log('Click');
    }

@mwubgadeashish
Copy link
Author

I am not sure but does it has something to do with events in

adding events in RangeSelectorButton.js

componentDidMount () {
const button = this.getButtonIndex();
if (button > -1) return; // Button already present

const { count, type, children } = this.props;
const buttons = [
  ...this.getButtons(),
  {
    count,
    type,
    text: children
  }
];
this.updateRangeSelectorButtons(buttons);

}

@mwubgadeashish
Copy link
Author

@whawker can you please help me on this?

@whawker whawker closed this as completed in d4e9047 Mar 7, 2018
@whawker
Copy link
Owner

whawker commented Mar 7, 2018

Hi sorry, was not aware RangeSelector buttons supported click events.

I've just published react-jsx-highstock@2.2.1 which adds support for this use case, which works in the way you assumed

<RangeSelector selected={1}>
  <RangeSelector.Button count={24} type="hour" onClick={this.handleClick}>P</RangeSelector.Button>
  <RangeSelector.Button count={1} type="day">1d</RangeSelector.Button>
  <RangeSelector.Button count={2} type="day">2d</RangeSelector.Button>
  <RangeSelector.Button count={1} type="week">1w</RangeSelector.Button>
  <RangeSelector.Button count={1} type="month">1m</RangeSelector.Button>
  <RangeSelector.Button type="all">all</RangeSelector.Button>
</RangeSelector>

@mwubgadeashish
Copy link
Author

@whawker I have update react-jsx-highstock@2.2.1 and i can see the changes but unfortunately I can not see the event has been called. On my side i have not done any changes in my code.
Please let me know if i need to make any changes on my side.

Thanks,
Ashish

@mwubgadeashish
Copy link
Author

screen shot 2018-03-07 at 8 30 01 am

@whawker
Copy link
Owner

whawker commented Mar 7, 2018

Hi @mwubgadeashish here is an example of Range Selector buttons with onClick events.

@mwubgadeashish
Copy link
Author

mwubgadeashish commented Mar 8, 2018

@whawker this is really helpful and i have a last question, how does other properties works with range selector ex: verticalAlign (bottom), size of button and etc.
I have tried it using Options and adding direct property but did not worked (see below sample)

https://www.highcharts.com/docs/chart-concepts/range-selector

@mwubgadeashish
Copy link
Author

I am not sure what can be the issue but things works well with your example (above) and does not work with my code: Ex: range selector shows at bottom of chart.

<RangeSelector.Button count={1} type="day">1 day</RangeSelector.Button>
<RangeSelector.Button count={1} type="week">1 week</RangeSelector.Button>
<RangeSelector.Button count={1} type="month">1 month</RangeSelector.Button>
<RangeSelector.Button type="all">All Time</RangeSelector.Button>

@mwubgadeashish
Copy link
Author

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

No branches or pull requests

2 participants