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

Ensure withFocusReturn's context props are not passed to wrappedElement #17354

Merged
merged 2 commits into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -88,7 +88,7 @@ function withFocusReturn( options ) {

const stack = [
...without(
this.props.focusHistory,
this.props.focus.focusHistory,
...ownFocusedElements
),
activeElementOnMount,
Expand All @@ -109,15 +109,15 @@ function withFocusReturn( options ) {
onFocus={ this.setIsFocusedTrue }
onBlur={ this.setIsFocusedFalse }
>
<WrappedComponent { ...this.props } />
<WrappedComponent { ...this.props.childProps } />
</div>
);
}
}

return ( props ) => (
<Consumer>
{ ( context ) => <FocusReturn { ...props } { ...context } /> }
{ ( context ) => <FocusReturn childProps={ props } focus={ context } /> }
</Consumer>
);
};
Expand Down
Expand Up @@ -51,13 +51,20 @@ describe( 'withFocusReturn()', () => {
expect( wrappedElementShallow.children[ 0 ].type ).toBe( 'textarea' );
} );

it( 'should pass additional props through to the wrapped element', () => {
it( 'should pass own props through to the wrapped element', () => {
const renderedComposite = renderer.create( <Composite test="test" /> );
const wrappedElement = renderedComposite.root.findByType( Test );
// Ensure that the wrapped Test element has the appropriate props.
expect( wrappedElement.props.test ).toBe( 'test' );
} );

it( 'should not pass any withFocusReturn context props through to the wrapped element', () => {
const renderedComposite = renderer.create( <Composite test="test" /> );
const wrappedElement = renderedComposite.root.findByType( Test );
// Ensure that the wrapped Test element has the appropriate props.
expect( wrappedElement.props.focusHistory ).toBeUndefined();
} );

it( 'should not switch focus back to the bound focus element', () => {
const mountedComposite = renderer.create( <Composite /> );

Expand Down