Hacker News new | ask | show | jobs
by humblebee 3188 days ago
We use portals quite a bit in our application and they always are a pain to test. This is what excites me the most about React supporting them natively. Hopefully this means that enzymejs will be able to easily walk down and seamlessly jump into a different part of the DOM without having to use references to adjust.

Portals are helpful when using content overflow in modals. For example, we have a modal which contains a form and that form has an autocomplete text box. When we render the autocomplete part, we need to render it outside of the modal, otherwise the overflow policy blocks the contents and does not allow the autocomplete are to appear over / outside of the modal.

The use of portals also make it easier to support screen readers through the aria tags by allowing the application to quickly block the background of the application and allow the screen reader to focus on the content presented to the user.

1 comments

This does worry me a bit though. There is probably a reason they are difficult to test, because they go against the React DOM pattern of a component only having control over the DOM nodes inside it. Call me a purist but this seems like a deviation from React's functional roots and going against the very problem React was trying to solve in the first place.
The feature is mostly intended for rendering into nodes not managed by React. Such as a document child that is sibling to the application root.
That may be true, but not having this possibility has made react near unusable for a lot of common UI patterns on the web.