-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ie11): make text field and text area active states work (#4)
* fix(ie11): make text field and text area active states work * trigger deploy
- Loading branch information
1 parent
d25aa29
commit 9b67d33
Showing
13 changed files
with
543 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es6: true | ||
es6: true, | ||
jest: true | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Modifiers | ||
|
||
Use these modifiers with `.ray-text-field` or `.ray-text-area` class. | ||
|
||
| Selector | Description | | ||
| --------------------------------- | --------------------------------------------------- | | ||
| .ray-text-field--compact | Selector for applying compact styles | | ||
| .ray-text-field--active | Selector for applying active/focus styles | | ||
| .ray-text-field--has-value | Selector for applying styles when field has value | | ||
| .ray-text-field--placeholder-mode | Selector for applying placeholder styles (no value) | | ||
| .ray-text-field--disabled | Selector for applying disabled styles | | ||
| .ray-text-field--error | Selector for applying error styles | | ||
|
||
## JavaScript | ||
|
||
Text fields: | ||
|
||
```javascript | ||
import { TextField } from '@wework/ray'; | ||
TextField.createAll(); | ||
// or | ||
TextField.create(document.querySelector('.ray-text-field')); | ||
``` | ||
|
||
Textareas: | ||
|
||
```javascript | ||
import { TextArea } from '@wework/ray'; | ||
TextArea.createAll(); | ||
// or | ||
TextArea.create(document.querySelector('.ray-text-area')); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const CSS_CLASSES = { | ||
TEXT_FIELD: { | ||
BASE: 'ray-text-field', | ||
ACTIVE: 'ray-text-field--active', | ||
EL__INPUT: 'ray-text-field__input', | ||
HAS_VALUE: 'ray-text-field--has-value' | ||
}, | ||
TEXT_AREA: { | ||
BASE: 'ray-text-area', | ||
ACTIVE: 'ray-text-area--active', | ||
EL__INPUT: 'ray-text-area__input', | ||
HAS_VALUE: 'ray-text-area--has-value' | ||
} | ||
}; | ||
|
||
export const STRINGS = { | ||
TEXT_FIELD: { | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_FIELD.BASE}` | ||
}, | ||
TEXT_AREA: { | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_AREA.BASE}` | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { CSS_CLASSES, STRINGS } from './constants'; | ||
import { validateNodeType, isTargetingItself } from '../../global/js/util'; | ||
|
||
class _InputComponent { | ||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
|
||
static createAll(target = document, _options = {}) { | ||
// Finds all instances of init selector on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
|
||
validateNodeType(target); | ||
|
||
if (isTargetingItself(target, options)) { | ||
this.create(target, options); | ||
} else { | ||
const textFields = [...target.querySelectorAll(options.initSelector)]; | ||
textFields.forEach(textField => this.create(textField, options)); | ||
} | ||
} | ||
|
||
constructor(root) { | ||
this._root = root; | ||
this._inputElement = this._root.querySelector( | ||
`.${this.constructor.cssClasses.EL__INPUT}` | ||
); | ||
|
||
if (!this._inputElement) { | ||
throw new Error( | ||
`TextField must have an input element with a class of .${ | ||
this.constructor.cssClasses.EL__INPUT | ||
}` | ||
); | ||
} | ||
|
||
this._bindEventListeners(); | ||
|
||
this.constructor.instances.set(this._root, this); | ||
} | ||
|
||
_bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
} | ||
|
||
value() { | ||
// Current value of the TextField | ||
return this._inputElement.value; | ||
} | ||
|
||
set(value) { | ||
this._inputElement.value = value; | ||
} | ||
|
||
onFocus = () => { | ||
this._root.classList.add(this.constructor.cssClasses.ACTIVE); | ||
}; | ||
|
||
onBlur = () => { | ||
this._root.classList.remove(this.constructor.cssClasses.ACTIVE); | ||
|
||
if (this.value()) { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
}; | ||
|
||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
|
||
this.constructor.instances.delete(this._root); | ||
} | ||
} | ||
|
||
class TextField extends _InputComponent { | ||
static instances = new WeakMap(); | ||
|
||
static get cssClasses() { | ||
return CSS_CLASSES.TEXT_FIELD; | ||
} | ||
|
||
static get strings() { | ||
return STRINGS.TEXT_FIELD; | ||
} | ||
} | ||
|
||
class TextArea extends _InputComponent { | ||
static instances = new WeakMap(); | ||
|
||
static get cssClasses() { | ||
return CSS_CLASSES.TEXT_AREA; | ||
} | ||
|
||
static get strings() { | ||
return STRINGS.TEXT_AREA; | ||
} | ||
} | ||
|
||
export { TextField, TextArea }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Select from './components/select'; | ||
import { TextField, TextArea } from './components/text-field'; | ||
|
||
export { Select }; // eslint-disable-line import/prefer-default-export | ||
export { Select, TextField, TextArea }; |
Oops, something went wrong.