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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modal] Convert the modal to a function #2341

Closed
wants to merge 3 commits into from

Conversation

LauraAubin
Copy link
Contributor

@LauraAubin LauraAubin commented Oct 22, 2019

WHY are these changes introduced?

Part of #1995

WHAT is this pull request doing?

Some notable changes,

  • The activator now uses useRef instead of createRef.
  • The external activator example needs to call requestAnimationFrame when focusing the button.

How to 馃帺

馃枼 Local development instructions
馃棐 General tophatting guidelines
馃搫 Changelog guidelines

馃帺 checklist

@LauraAubin LauraAubin changed the base branch from master to v5.0.0 October 22, 2019 17:14
@BPScott BPScott mentioned this pull request Oct 22, 2019
className={styles.Body}
onScrolledToBottom={onScrolledToBottom}
const Modal: React.FunctionComponent<CombinedProps> & {
Section: typeof Section;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Card explains why this typing is needed:

TypeScript can't generate types that correctly infer the typing of subcomponents so explicitly state the subcomponents in the type definition. Letting this be implicit works in this project but fails in projects that use generated *.d.ts files.

const [iframeHeight, setIframeHeight] = useState(IFRAME_LOADING_HEIGHT);

const headerId = getUniqueID();
const activatorRef = React.useRef<HTMLDivElement>(null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should these still be private?

}: CombinedProps) {
const [iframeHeight, setIframeHeight] = useState(IFRAME_LOADING_HEIGHT);

const headerId = getUniqueID();
Copy link
Member

Choose a reason for hiding this comment

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

getUniqueID/createUniqueIdFactory is problematic as it's not stable between rerenders (i.e. every time you rerender the component then you get a new Id which causes pointless changes to the DOM). Use the useUniqueId hook instead. See #2079 for more info

Suggested change
const headerId = getUniqueID();
const headerId = useUniqueId('modal-header');

footer,
primaryAction,
secondaryActions,
polaris: {intl},
Copy link
Member

Choose a reason for hiding this comment

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

A big part of moving towards functional components is that we can remove the withAppProvider HoC that provides this polaris prop. We've got a handful of custom hooks that replace these values of polaris

Remove this and the withAppProvider Hoc and instead do:

const i18n = useI18n();

// ...

i18n.translate('Polaris.SomeKey');

</WithinContentContext.Provider>
);

function handleEntered() {
Copy link
Member

Choose a reason for hiding this comment

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

These functions need to be wrapped in useCallback so we don't trigger rerenders of the elements that they get passed into

@BPScott BPScott closed this Oct 25, 2019
@BPScott BPScott deleted the convert-modal-to-function branch May 22, 2021 00:47
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.

None yet

2 participants