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

fix(AbstractNav): allow passed in refs to be properly forwarded #4031

Merged
merged 8 commits into from Aug 9, 2019

Conversation

@bpas247
Copy link
Member

bpas247 commented Jul 10, 2019

Abstract Nav should be forwarding its ref to the underlying component, so that Nav (and any other components using this) can get the proper ref.

Fixes #4012.

src/AbstractNav.js Outdated Show resolved Hide resolved
src/AbstractNav.js Outdated Show resolved Hide resolved
src/AbstractNav.js Show resolved Hide resolved
src/AbstractNav.js Outdated Show resolved Hide resolved
Co-Authored-By: Jimmy Jia <tesrin@gmail.com>
@bpas247

This comment was marked as resolved.

Copy link
Member Author

bpas247 commented Jul 24, 2019

it('Should have tablist and tab roles', () => {
const wrapper = mount(
<Nav role="tablist">
<Nav.Link key={1}>Tab 1 content</Nav.Link>
<Nav.Link key={2}>Tab 2 content</Nav.Link>
</Nav>,
);
wrapper.assertSingle('div[role="tablist"]');
wrapper.find('a[role="tab"]').length.should.equal(2);
});

So I'm not exactly sure why this test is failing. The ref functionality shouldn't change anything about the assertion being made on Line 220, yet it's still failing.

What's interesting is that if I change this line to:

wrapper.assertSingle('Nav[role="tablist"]'); 

It passes 🤔 Could this be testing an implementation detail?

EDIT: It seems to be testing an implementation detail, which is causing the false negatives. I changed the selectors a bit in bf5cbc1

bpas247 added a commit that referenced this pull request Jul 27, 2019
Migrate Input and List Group components to properly forward
passed in refs to the underlying component.

Also, replace HOC functionality with custom hooks.

Relevant to #4012 and #4031.
bpas247 added 3 commits Jul 27, 2019
This reduces the complexity of the AbstractNav implementation,
especially in regards to how the contexts are integrated with it.
This fixes the assertion issues caused by the selectors testing
implementation details to find the DOM elements, rather than
testing for something that is gauranteed to be in the
implementation (E.g. the class `nav` on the Nav component, since
it's part of the Bootstrap design spec) of the rendered DOM
element.
Currently, we use a ref to gain access to the underlying
component to implement our own functionality. However, this causes
an issue with not allowing the user to forward their own ref
to gain access to the underlying component. using `useMergedRefs`,
we are able to forward both refs to the underlying component.
@bpas247 bpas247 requested review from jquense and taion Jul 27, 2019
@bpas247

This comment has been minimized.

Copy link
Member Author

bpas247 commented Jul 27, 2019

(Just a side-note, we should consider releasing useMergedRefs as a standalone package, it's a pretty useful hook 👀)

@taion
taion approved these changes Jul 27, 2019
Copy link
Member

taion left a comment

@jquense any reason why useMergedRefs isn't in @restart/hooks?

@bpas247 bpas247 mentioned this pull request Aug 7, 2019
13 of 13 tasks complete
@bpas247 bpas247 changed the title fix: Abstract Nav forwarding ref fix(AbstractNav): allow passed in refs to be properly forwarded Aug 9, 2019
@jquense

This comment has been minimized.

Copy link
Member

jquense commented Aug 9, 2019

no reason, we should probably put it there!

@jquense
jquense approved these changes Aug 9, 2019
@taion

This comment has been minimized.

Copy link
Member

taion commented Aug 9, 2019

i updated this to use restart/hooks; merging so i can cut a release

@bpas247

This comment has been minimized.

Copy link
Member Author

bpas247 commented Aug 9, 2019

Thinking we’ll need to update react-overlays to use usedMergedRefs from @restart/hooks rather than its local implementation of it.

@taion

This comment has been minimized.

Copy link
Member

taion commented Aug 9, 2019

sure, but we can do that later

@taion taion merged commit bda567f into master Aug 9, 2019
5 checks passed
5 checks passed
codecov/patch 97.72% of diff hit (target 94.96%)
Details
codecov/project 94.98% (+0.01%) compared to 9993869
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
@taion taion deleted the fix/abstract-nav-ref-forwarder branch Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.