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

Search shortcut breaks forms #398

Closed
markeganfuller opened this issue Jul 18, 2017 · 7 comments
Closed

Search shortcut breaks forms #398

markeganfuller opened this issue Jul 18, 2017 · 7 comments
Assignees
Labels
bug

Comments

@markeganfuller
Copy link

@markeganfuller markeganfuller commented Jul 18, 2017

Search shortcut breaks forms

We have a number of forms in our mkdocs site which are broken by the search shortcut (s / f).

Expected behavior

Search only opens when not focused on a form element.

Actual behavior

When typing in a form field (e.g. input / text area) an s or f will open the search.

Steps to reproduce the bug

  1. Add the following to a test page
<form>
<input></input>
<textarea></textarea>                                                                                                
</form>
  1. Attempt to write sausages in the input / text area

Package versions

  • Python: Python 2.7.13
  • MkDocs: 0.16.3
  • Material: 1.7.4

Potential fix

I think the code to fix this would be a change to: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/javascripts/application.js#L340

Something like this to check if the current focused element is part of a form:

if (document.activeElement.form === undefined) {
  if (ev.keyCode === 70 || ev.keyCode === 83) {
    query.focus()
    ev.preventDefault()
  }
}

That seems to work in testing but doesn't pass the 'flow' check and I'm not quite familiar enough with js to quickly make this work.

@squidfunk
Copy link
Owner

@squidfunk squidfunk commented Jul 18, 2017

That's indeed a bug, thanks for reporting and the potential fix!

@squidfunk
Copy link
Owner

@squidfunk squidfunk commented Jul 25, 2017

Fixed in #407, will be released shortly with 1.7.5.

@squidfunk squidfunk closed this Jul 25, 2017
@Kobzol
Copy link

@Kobzol Kobzol commented Jan 22, 2019

This is still a problem with Chrome even in 3.0.5. document.activeElement.form returns null for <input> tags, therefore the search gets focused everytime I try to write s or f into an input.

@squidfunk
Copy link
Owner

@squidfunk squidfunk commented Jan 22, 2019

Please provide a reproducible scenario (with configuration + Markdown, or even better, a repo), then we can fix it.

@Kobzol
Copy link

@Kobzol Kobzol commented Jan 22, 2019

Can I send you the website directly? Try this: https://docs.it4i.cz/modules-matrix/ focus the Module Filter input box and type "s". The repository for the website can be found here: https://code.it4i.cz/sccs/docs.it4i.cz.

@squidfunk
Copy link
Owner

@squidfunk squidfunk commented Jan 22, 2019

I've inspected your code - for your purposes: you can wrap the input in a form and the error should be gone. I may improve the detection of active form fields so it doesn't trigger for input fields that are not wrapped inside forms when I find the time at some point in the future.

@Kobzol
Copy link

@Kobzol Kobzol commented Jan 22, 2019

OK. That's an easy workaround, you're right. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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