Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Fix https://github.com/readmeio/api-explorer/issues/42#48

Merged
domharrington merged 15 commits intomasterfrom
feature/authentication-box-without-auth
Oct 25, 2017
Merged

Fix https://github.com/readmeio/api-explorer/issues/42#48
domharrington merged 15 commits intomasterfrom
feature/authentication-box-without-auth

Conversation

@uppal101
Copy link
Copy Markdown
Contributor

No description provided.

@domharrington
Copy link
Copy Markdown
Member

When auth warning is shown, then focus the auth input and scroll into view.

Right now if the auth box is visible and the cursor is typed anywhere, the focus is being stoled into the auth box.

const { auth } = this.props;
return (
<div className="row">
<div className="row" ref={input => (this.input = input)}>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need this here?

<div className="col-xs-6">
<label htmlFor="user">username</label>
<input
ref={input => input && auth && input.focus()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there ever a possibility that input isn't going to be defined here? Do we need to do this part: input &&?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the best way to test this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if input && isn't there it cannot read focus of null. I got it from the second response since Oauth2 and ApiKey aren't classes https://stackoverflow.com/questions/28889826/react-set-focus-on-input-after-render


Basic.propTypes = {
change: PropTypes.func.isRequired,
auth: PropTypes.bool.isRequired,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this context, naming this variable auth doesn't really mean too much? Would it make more sense to call it focus or something?

switch (props.scheme.type) {
case 'oauth2':
return <Oauth2 {...props} change={change} />;
return <Oauth2 {...props} change={change} auth={props.auth} />;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should already get passed down via the {...props}? or am i misunderstanding?

const onChange = jest.fn();
const securityInput = mount(<SecurityInput {...props} onChange={onChange} />);
const securityInput = mount(
<SecurityInput {...props} onChange={onChange} scrollIntoView={scrollIntoView} />,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you need to pass scrollIntoView into the SecurityInput? It's not a prop in there is it?

@domharrington
Copy link
Copy Markdown
Member

If the element is already in the view, calling scrollIntoView() on it causes some jumpiness and makes only the input the top thing. In my testing, calling .focus() on the input scrolls it into view as well. Did you experience this?

@domharrington
Copy link
Copy Markdown
Member

Although we dont have a direct test for this, the code path gets hit by this test:

jest.useFakeTimers();
const doc = mount(<Doc {...props} />);
doc.instance().onSubmit();
expect(doc.state('showAuthBox')).toBe(true);
jest.runAllTimers();
expect(doc.state('needsAuth')).toBe(true);

I dont particularly like all the wiring with the references everywhere, but i think it's okay for now until we add a better state management library possibly, although i dont even know if that would help with our component heirarchy.

@domharrington domharrington merged commit 865dcf0 into master Oct 25, 2017
@erunion erunion deleted the feature/authentication-box-without-auth branch July 1, 2019 16:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants