h5p-lib-controls
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "h5p-lib-controls", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Library for adding user input to web applications", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -124,2 +124,3 @@ import { setAttribute, removeAttribute, hasAttribute } from 'h5p-sdk/src/scripts/utils/elements'; | ||
* @param {HTMLElement} el | ||
* @param {number} position | ||
* | ||
@@ -129,2 +130,20 @@ * @fires Controls#addElement | ||
*/ | ||
insertElementAt(el, position) { | ||
this.elements.splice(position, 0, el); | ||
this.firesEvent('addElement', el); | ||
if (this.elements.length === 1) { // if first | ||
this.setTabbable(el); | ||
} | ||
} | ||
/** | ||
* Add controls to an element | ||
* | ||
* @param {HTMLElement} el | ||
* | ||
* @fires Controls#addElement | ||
* @public | ||
*/ | ||
removeElement(el) { | ||
@@ -131,0 +150,0 @@ this.elements = without([el], this.elements); |
@@ -9,3 +9,3 @@ import Controls from '../src/scripts/controls'; | ||
controls = new Controls(); | ||
elements = [document.createElement("div"), document.createElement("div"), document.createElement("div")]; | ||
elements = [document.createElement("div"), document.createElement("a"), document.createElement("p")]; | ||
}); | ||
@@ -23,2 +23,11 @@ | ||
it("should add elements at a given position", function () { | ||
// add elements to controls | ||
elements.forEach(el => controls.insertElementAt(el, 0)); | ||
expect(controls.elements[0]).toBe(elements[2]); | ||
expect(controls.elements[1]).toBe(elements[1]); | ||
expect(controls.elements[2]).toBe(elements[0]); | ||
}); | ||
it("should move tabindex on next", function () { | ||
@@ -25,0 +34,0 @@ // add elements to controls |
Sorry, the diff of this file is not supported yet
863
76246