Skip to content

Instantly share code, notes, and snippets.

@sglanzer-deprecated
Created December 23, 2016 01:36
Show Gist options
  • Save sglanzer-deprecated/a23fc64300f3ff9c3d0c029d7dde9b26 to your computer and use it in GitHub Desktop.
Save sglanzer-deprecated/a23fc64300f3ff9c3d0c029d7dde9b26 to your computer and use it in GitHub Desktop.
Focusable svgs
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ['x', 'y','width', 'height', 'data-tabindex'],
tagName: 'rect',
'data-tabindex': '0'
});
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ['href'],
classNames: ['svg-anchor'],
href: '#',
tagName: 'a',
click() {
return false;
},
focusIn() {
this.onFocusEvent(this.name, 'in')
},
focusOut() {
this.onFocusEvent(this.name, 'out')
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
showFocusEvent(name, event) {
this.setProperties({
name,
event
})
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.svg-anchor {
pointer-events: all;
}
.svg-anchor:focus {
fill: pink;
stroke: red;
stroke-width: 1;
}
<svg width=100 height=100>
{{#svg-anchor name='1' onFocusEvent=(action 'showFocusEvent')}}
{{a-rect x=0 y=0 width=40 height=40}}
{{/svg-anchor}}
{{#svg-anchor name='2' onFocusEvent=(action 'showFocusEvent')}}
{{a-rect x=60 y=0 width=40 height=40}}
{{/svg-anchor}}
{{#svg-anchor name='3' onFocusEvent=(action 'showFocusEvent')}}
{{a-rect x=0 y=60 width=40 height=40}}
{{/svg-anchor}}
{{#svg-anchor name='4' onFocusEvent=(action 'showFocusEvent')}}
{{a-rect x=60 y=60 width=40 height=40}}
{{/svg-anchor}}
</svg>
<br>
<br>
<div>Focused element: {{name}}</div>
<br>
<div>Focus event: {{event}}</div>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment