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

feat: modifier byAttribute for dynamic attribute autofocuse #1

Merged
merged 4 commits into from
May 14, 2019
Merged

feat: modifier byAttribute for dynamic attribute autofocuse #1

merged 4 commits into from
May 14, 2019

Conversation

Scrum
Copy link
Contributor

@Scrum Scrum commented May 13, 2019

No description provided.

@Scrum
Copy link
Contributor Author

Scrum commented May 14, 2019

@botre ping

@botre
Copy link
Collaborator

botre commented May 14, 2019

Hello,

Thank you for your pull request!
If you want to dynamically set the autofocus attribute you can already do so natively (see snippet below), I don't understand the exact added value considering this.

Am I missing something here?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  </head>

  <body>
    <div id="app">
      <input type="text" />
      <input type="text" :autofocus="af" />
    </div>
    <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            af: true
          };
        }
      });
    </script>
  </body>
</html>

@Scrum
Copy link
Contributor Author

Scrum commented May 14, 2019

@botre Hi

Am I missing something here?

you all say right, but I have a situation in which I need to clearly trigger a focus event, like this)
Blocked autofocusing on a form control in a cross-origin subframe

@botre
Copy link
Collaborator

botre commented May 14, 2019

Oh I see,

What do you think about the following implementation?
Instead of using the autofocus attribute to control whether or not to trigger the event, it uses a directive argument instead.

// Register a global custom directive called `v-focus`
const directive = {
  // When the bound element is inserted into the DOM...
  inserted: function(el, binding) {
    if (typeof binding.value !== "undefined" && !binding.value) {
      return;
    }
    el.focus();
  }
};

export default directive;
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Demo</title>
  </head>
  <body>
    <div id="app">
      <input v-autofocus="isDesktop" type="text" />
    </div>
    <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
    <script src="./dist/vue-autofocus-directive.js"></script>
    <script>
      Vue.directive("autofocus", window["vue-autofocus-directive"].default);
      new Vue({
        el: "#app",
        data() {
          return {
            isDesktop: true
          };
        }
      });
    </script>
  </body>
</html>

BR

@Scrum
Copy link
Contributor Author

Scrum commented May 14, 2019

@botre Yes, your decision is more elegant, but unfortunately it carries less information about actions, although it increases your imagination)

@botre botre merged commit 8357484 into byteboomers:master May 14, 2019
@botre
Copy link
Collaborator

botre commented May 14, 2019

Merged into master, built & deployed to NPM as 1.0.2.

Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants