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

How to Add Custom Button Text for each Step #89

Closed
digitalbridge opened this issue Mar 9, 2018 · 4 comments
Closed

How to Add Custom Button Text for each Step #89

digitalbridge opened this issue Mar 9, 2018 · 4 comments
Labels
UpVotes Needed If you like this feature request, please upvote Useful Tips

Comments

@digitalbridge
Copy link

Is it possible to somehow have different text on buttons on every step rather than the same throughout all steps? Would be great if you could, for example, have 'nextButtonText' value inside the definition of each component.

@newbreedofgeek newbreedofgeek added Discussion UpVotes Needed If you like this feature request, please upvote and removed Discussion labels Mar 25, 2018
@newbreedofgeek
Copy link
Owner

Hi @digitalbridge - I like the idea but at this point in time its not possible, I'll flag this as a UpVotes Needed and if we get many upvotes we may plan it in a release but at this point we dont have have any plans for this.

Horrible workaround would be to use JavaScript to inject custom text into the buttons after page load... (sorry...)

@newbreedofgeek newbreedofgeek changed the title Different button text for every step Custom Button Text for each Step Mar 25, 2018
@logankoester
Copy link

I've successfully worked around this limitation by passing a component to nextButtonText and setting its state from each step component by reference. It does echo a prop-types warning, but it's working well so for now I can live with that:

class NextButtonText extends Component {
  constructor(props: {}) {
    super(props);
    this.state = { text: 'Continue', }
  }

  render() {
    return(this.state.text);
  }
}
class MySteps extends Component {
  constructor(props: {}) {
    super(props);
    this.setNextButtonText = this.setNextButtonText.bind(this);
    this.state = {
      steps: [
        { name: 'StepOne', component: <StepOne setNextButtonText={ this.setNextButtonText } /> },
        { name: 'StepTwo', component: <StepTwo setNextButtonText={ this.setNextButtonText } /> },
      ]
    };
  }

  setNextButtonText(value) {
    if (this.nextButtonText) {
      this.nextButtonText.setState({ text: value });
    }
  }

  render() {
    return (
        <StepZilla 
          nextButtonText={<NextButtonText ref={(nbt) => { this.nextButtonText = nbt; }} />}
          steps={this.state.steps} />
    );
  }
}

@newbreedofgeek
Copy link
Owner

@logankoester thats very smart, good job! I'll close this off for now. If someone else has the same request I'll reopen and activate the "Upvotes" tag.

@newbreedofgeek newbreedofgeek changed the title Custom Button Text for each Step How to Add Custom Button Text for each Step Apr 4, 2018
@TonyWu5
Copy link

TonyWu5 commented Mar 11, 2020

Another approach to this is to utilize the step that gets returned from onStepChange and conditionally change the nextButtonText based on the step.

const MySteps = props => {
  const [nextBtnText, setNextBtnText] = useState('Agree & Continue');

  const onStepChange = step => {
    if (step !== 0) {
      setNextBtnText('Save & Continue');
    } else {
      setNextBtnText('Agree & Continue');
    }
  };

  const steps = [
    {
      name: 'Step 1',
      component: <Step1 />,
    },
    {
      name: 'Step 2',
      component: <Step2 />,
    },
    {
      name: 'Step 3',
      component: <Step3 />,
    }
  ];

  return (
          <StepZilla
            steps={steps}
            nextButtonText={nextBtnText}
            onStepChange={onStepChange}
          />
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UpVotes Needed If you like this feature request, please upvote Useful Tips
Projects
None yet
Development

No branches or pull requests

4 participants