templating-resources
templating-resources copied to clipboard
focus.one-time unexpected behaviour
I'm submitting a bug report
- Library Version: 1.2.0
Please tell us about your environment:
-
Operating System: Linux (Ubuntu)
-
Node Version: 6.9.4
-
NPM Version: 3.10.10
-
JSPM JSPM 0.16.48
-
Browser: Chrome 55
-
Language: TypeScript 2.1.4
Current behavior: If I want an element focused on render, but I'm not interested in keeping track of its focus state after that, I might do something like this:
<button focus.one-time="true">My Button</button>
In this case, attaching event listeners to the element only results in needless overhead.
Expected/desired behavior: The Focus custom attribute should check if the binding mode is two-way and if not, should not attach event listeners to the element.
While we're on the subject: I would expect the default binding mode of focus to be one-way. I usually bind it to an expression that cannot be assigned to:
<a href="#" focus.bind="item === defaultItem">${item.name}</a>
If focus changes and comes back to this link, I'll get an error:
Uncaught Error: Binding expression "item === defaultItem" cannot be assigned to.
I can't speak for other developers, but I expect the most common use-case for the focus attribute to set initial focus, not to keep a property updated on whether an item is focused or not.
attach focus from dialog is what you want.. https://github.com/aurelia/dialog/blob/master/src/attach-focus.ts question is how many developers thought about using focus.one-way