Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Last active June 6, 2018 21:03
Show Gist options
  • Save AshleyGrant/7587f1453cb2632fa09b6fe542d9717c to your computer and use it in GitHub Desktop.
Save AshleyGrant/7587f1453cb2632fa09b6fe542d9717c to your computer and use it in GitHub Desktop.
Working with Focus
<template>
<require from="./some-element"></require>
<label for="hasFocus">Has Focus:</label> <input id="hasFocus" type="checkbox" checked.bind="focus" />
<div>
Custom Element:
<some-element has-focus.bind="focus" text.bind="text"></some-element>
</div>
<div>
Regular text box:
<input type="text" value.bind="text" />
</div>
</template>
export class App {
focus = false;
text = 'Hello';
setText() {
this.text += '-';
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
<template>
<input ref="textbox" type="text" value.bind="text" focus.bind="hasFocus" />
</template>
import {bindable, bindingMode} from 'aurelia-framework';
export class SomeElement {
@bindable({ defaultBindingMode: bindingMode.twoWay }) text;
@bindable({ defaultBindingMode: bindingMode.twoWay }) hasFocus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment