Skip to content

Commit

Permalink
Merge pull request #1117 from Shopify/modal-scrollable-bottom-callback
Browse files Browse the repository at this point in the history
[Modal] Add onScrolledToBottom prop to Modal
  • Loading branch information
posth authored Mar 1, 2019
2 parents dc91c87 + e9f04f7 commit a043c44
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

- Track Polaris version information in App Bridge actions
- Re-added the navigation’s border-right ([#1096](https://github.com/Shopify/polaris-react/pull/1096))
- Added `onScrolledToBottom` prop to `Modal` ([#1117](https://github.com/Shopify/polaris-react/pull/1117))

### Bug fixes

Expand Down
9 changes: 8 additions & 1 deletion src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface Props extends FooterProps {
onIFrameLoad?(evt: React.SyntheticEvent<HTMLIFrameElement>): void;
/** Callback when modal transition animation has ended (stand-alone app use only) */
onTransitionEnd?(): void;
/** Callback when the bottom of the modal content is reached */
onScrolledToBottom?(): void;
}
export type CombinedProps = Props & WithAppProviderProps;

Expand Down Expand Up @@ -210,6 +212,7 @@ export class Modal extends React.Component<CombinedProps, State> {
primaryAction,
secondaryActions,
polaris: {intl},
onScrolledToBottom,
} = this.props;

const {iframeHeight} = this.state;
Expand Down Expand Up @@ -251,7 +254,11 @@ export class Modal extends React.Component<CombinedProps, State> {
style={{height: `${iframeHeight}px`}}
/>
) : (
<Scrollable shadow className={styles.Body}>
<Scrollable
shadow
className={styles.Body}
onScrolledToBottom={onScrolledToBottom}
>
{body}
</Scrollable>
);
Expand Down
42 changes: 42 additions & 0 deletions src/components/Modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,48 @@ class ModalExample extends React.Component {
}
```

### Modal with scroll listener

<!-- example-for: web -->

Use to implement infinite scroll of modal content.

```jsx
class ModalExample extends React.Component {
state = {
active: true,
};

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

return (
<div style={{height: '500px'}}>
<Button onClick={this.handleChange}>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}));
};
}
```

### Warning modal

<!-- example-for: android, ios -->
Expand Down

0 comments on commit a043c44

Please sign in to comment.