-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
className={styles.Body} | ||
onScrolledToBottom={onScrolledToBottom} | ||
const Modal: React.FunctionComponent<CombinedProps> & { | ||
Section: typeof Section; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
src/components/Modal/Modal.tsx
Outdated
}: CombinedProps) { | ||
const [iframeHeight, setIframeHeight] = useState(IFRAME_LOADING_HEIGHT); | ||
|
||
const headerId = getUniqueID(); |
There was a problem hiding this comment.
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
const headerId = getUniqueID(); | |
const headerId = useUniqueId('modal-header'); |
src/components/Modal/Modal.tsx
Outdated
footer, | ||
primaryAction, | ||
secondaryActions, | ||
polaris: {intl}, |
There was a problem hiding this comment.
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');
src/components/Modal/Modal.tsx
Outdated
</WithinContentContext.Provider> | ||
); | ||
|
||
function handleEntered() { |
There was a problem hiding this comment.
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
WHY are these changes introduced?
Part of #1995
WHAT is this pull request doing?
Some notable changes,
useRef
instead ofcreateRef
.requestAnimationFrame
when focusing the button.How to 馃帺
馃枼 Local development instructions
馃棐 General tophatting guidelines
馃搫 Changelog guidelines
馃帺 checklist
README.md
with documentation changes