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

[Modal] Add onScrolledToBottom prop to Modal #1117

Merged
merged 1 commit into from
Mar 1, 2019

Conversation

posth
Copy link
Contributor

@posth posth commented Mar 1, 2019

WHY are these changes introduced?

Resolves #1116

When using Scrollable within Modal, and dynamically rendering its content, the Scrollable onScrolledToBottom handler isn't triggered.

See example of that issue

WHAT is this pull request doing?

The Modal's Scrollable onScrolledToBottom prop is brought up to Modal as a new prop.

The advantage is if content is scrollable, this new prop can handle callbacks without having to directly add the Scrollable component. Useful for infinite scrolling features, for example.

How to 🎩

Load the following playground code, you should be able to scroll to the bottom and see an alert pop-up.

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {Page, Modal, TextContainer} from '../src';

interface State {}

export default class Playground extends React.Component<never, State> {
  render() {
    return (
      <Page title="Playground">
        <Modal
          open
          title="Scrollable content"
          onClose={() => null}
          onScrolledToBottom={() => alert('scrollable bottom')}
        >
          {Array.from({length: 50}, (_, index) => (
            <Modal.Section>
              <TextContainer>
                <p>Item #{index}</p>
              </TextContainer>
            </Modal.Section>
          ))}
        </Modal>
      </Page>
    );
  }
}

🎩 checklist

@ghost
Copy link

ghost commented Mar 1, 2019

👋 Thanks for opening your first pull request. A contributor should give feedback soon. If you haven’t already, please check out the contributing guidelines. You can also join #polaris on the Shopify Partners Slack.

@BPScott BPScott temporarily deployed to polaris-react-pr-1117 March 1, 2019 16:08 Inactive
Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

This prop was much needed, thank you!! Can you add a new example for this in /components/Modal/README.md?

For example, using your playground code:

Modal with scroll listener

Use to implement infinite scroll of modal content.

class ModalScrollCallbackExample extends React.Component {
  state = {
    active: true,
  };

  render() {
    const {active} = this.state;

    return (
      <div style={{height: '500px'}}>
        <Button onClick={this.toggleModalVisibility}>Open</Button>
        <Modal
           open
           title="Scrollable content"
           onClose={this.toggleModalVisibility}
           onScrolledToBottom={() => alert('scrolled to bottom')}
         >
          {Array.from({length: 50}, (_, index) => (
            <Modal.Section>
              <TextContainer>
                <p>Item #{index}</p>
              </TextContainer>
            </Modal.Section>
          ))}
        </Modal>
      </div>
    );
  }

  toggleModalVisibility = () => {
    this.setState(({active}) => ({active: !active}));
  };
}

@chloerice
Copy link
Member

Be sure to update the change log via UNRELEASED.md too 😁

@chloerice
Copy link
Member

🚀 🚀 🚀

Added README modal infinite scroll listener example + updated changelog
@posth posth force-pushed the modal-scrollable-bottom-callback branch from f73070f to e9f04f7 Compare March 1, 2019 16:42
@BPScott BPScott requested a deployment to polaris-react-pr-1117 March 1, 2019 16:42 Abandoned
@posth posth merged commit a043c44 into master Mar 1, 2019
@ghost
Copy link

ghost commented Mar 1, 2019

🎉 Thanks for your contribution to Polaris React!

@amrocha amrocha temporarily deployed to production March 7, 2019 22:06 Inactive
@kaelig kaelig deleted the modal-scrollable-bottom-callback branch June 27, 2019 01:08
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.

4 participants