Skip to content

Instantly share code, notes, and snippets.

@billpull
Forked from dhindurthy/components.cx-modal.js
Created March 20, 2018 15:37
Show Gist options
  • Save billpull/454585b915222c942edebebdc1973542 to your computer and use it in GitHub Desktop.
Save billpull/454585b915222c942edebebdc1973542 to your computer and use it in GitHub Desktop.
modal-accessible
import Ember from 'ember';
export default Ember.Component.extend({
classNames:['cx-modal'],
attributeBindings: ['tabindex:tabindex','role:role'],
role:'dialog',
tabindex:0,
didRender(){
this.$().children().first().focus();
},
keyDown: function(event){
if(event.keyCode===9 ){
var nextElement =this.$(document.activeElement).next().length;
if(!event.shiftKey && nextElement===0){
event.preventDefault();
this.$().children().first().focus();
}
var prevElement =this.$(document.activeElement).prev().length;
if(event.shiftKey && prevElement===0){
event.preventDefault();
this.$().children().last().focus();
}
}
if(event.keyCode===27 ){
this.sendAction('closeModal');
}
},
focusOut(event){},
didDestroyElement(){
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
isModalVisible: false,
actions:{
toggleModal:function(){
this.set('isModalVisible', true);
},
closeModal: function(){
this.set('isModalVisible', false);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.cx-modal{
border: 5px solid #E35B44;
padding:20px;
margin:10px;
width:75%;
position: absolute;
z-index: 1;
background-color:white;
}
.note {
color:#E35B44;
}
<br>
<br>
{{outlet}}
<br>
<br>
<p>
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
{{#if isModalVisible}}
{{#cx-modal closeModal="closeModal"}}
<h3 tabindex=0>Heading in modal</h3>
<textarea></textarea><br>
<p>do whatever you want here</p>
<button {{action 'closeModal'}}>Close</button>
{{/cx-modal}}
{{/if}}
<input type="text">
<button {{action 'toggleModal'}}>Submit</button>
<p class="note"><i>Note: Click 'Submit' to open the dialog</i></p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
{
"version": "0.13.0",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment