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

onDismiss() not functioning #52

Closed
tlwirtz opened this issue May 10, 2017 · 7 comments
Closed

onDismiss() not functioning #52

tlwirtz opened this issue May 10, 2017 · 7 comments

Comments

@tlwirtz
Copy link

tlwirtz commented May 10, 2017

Issue summary

When using the Banner component and passing a function into the onDismiss prop it doesn't appear that the callback ever fires when the dismissal button is pressed.

Expected behavior

Expected the callback to fire when dismissal button is pressed.

Actual behavior

Clicking the dismissal button does not trigger the callback.

Steps to Reproduce the Problem

This is how I'm rendering the Banner. The component displays properly onscreen.

    <Banner title="test" status='warning' onDismiss={() => {console.log('dismissing')}}>
      <p>Just a test.</p>
    </Banner>

Specifications

  • Polaris version: 1.0.2
  • React version: 15.4.2
  • Browser: Chrome 58.0.3029
  • Device: Macbook Pro Retina (Mid 2014)
  • Operating System: macOS Sierra 10.12.4

NOTE: This repo is only used for reporting issues and new feature requests. We are not accepting pull requests at this point in time.

@lemonmade
Copy link
Member

Thanks for the issue, @tlwirtz. Should be fixed in 1.0.3.

@slyapustin
Copy link

@lemonmade This is not fixed (at least in 1.9.1).

@tmlayton
Copy link
Contributor

Hi @inoks, I checked out v1.9.1 and tried using the code sample you provided and it is working as expected. Are there other errors happening?

dismissing

@slyapustin
Copy link

@tmlayton Oh, yes that's works, sorry for misleading you.
But what is expected by me is to have some internal way to hide banner if dismiss button was clicked, without creating some external hide/display state.

@tmlayton
Copy link
Contributor

@inoks makes sense, although we avoid managing state within the components and leave it up to the consumer to handle.

@lakshyads
Copy link

lakshyads commented Jul 15, 2019

@tmlayton Oh, yes that's works, sorry for misleading you.
But what is expected by me is to have some internal way to hide banner if dismiss button was clicked, without creating some external hide/display state.

Hi @inoks @tmlayton, I am facing a similar problem. There is no internal way to hide the banner when dismiss button is clicked. You mentioned something about creating external hide/display state. Can you explain how that can be done as this is my first time working with Polaris components and i have had no luck trying to hide the banner.

@chloerice
Copy link
Member

chloerice commented Jul 15, 2019

@tmlayton Oh, yes that's works, sorry for misleading you.
But what is expected by me is to have some internal way to hide banner if dismiss button was clicked, without creating some external hide/display state.

Hi @inoks @tmlayton, I am facing a similar problem. There is no internal way to hide the banner when dismiss button is clicked. You mentioned something about creating external hide/display state. Can you explain how that can be done as this is my first time working with Polaris components and i have had no luck trying to hide the banner.

Hey @lakshyads, in the code that renders the Banner, you can use a boolean set on your state (let's say showBanner) to manage rendering the banner conditionally. So for instance, in your render method before your return, you can save the banner markup as a variable that is the Banner with whatever props you want if showBanner is true, and null if false. If you want the banner to initially show up and disappear on dismiss, you can set the initial state of showBanner as true, then in the callback that you set on the onDismiss prop you can this.setState({showBanner: false}).

class PageWithDismissableBanner extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      showBanner: true,
    }
  }

  handleBannerDismiss = () => {
    this.setState({showBanner: false})
  }

  render() {
    const {showBanner} = this.state;
    const dismissableBannerMarkup = showBanner ? (
      <Banner title="Your banner title" onDismiss={this.handleBannerDismiss}>
        <p>Your banner content</p>
      </Banner>
    ) : null

    return (
      <Page title="Your page title">
        {dismissableBannerMarkup}
        {your other page markup}
     </Page>
    );
  }
}

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

6 participants