@neovici/cosmoz-input
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -0,1 +1,8 @@ | ||
## [1.3.0](https://github.com/neovici/cosmoz-input/compare/v1.2.0...v1.3.0) (2021-02-09) | ||
### Features | ||
* adds allowed-pattern support ([9e73006](https://github.com/neovici/cosmoz-input/commit/9e73006d103fbb22c4d4fe82b4b75915d67aec46)) | ||
## [1.2.0](https://github.com/neovici/cosmoz-input/compare/v1.1.1...v1.2.0) (2021-02-09) | ||
@@ -2,0 +9,0 @@ |
@@ -8,3 +8,3 @@ import { html, nothing } from 'lit-html'; // eslint-disable-line object-curly-newline | ||
import { | ||
component, useCallback, useEffect | ||
component, useCallback, useEffect, useMemo | ||
} from 'haunted'; | ||
@@ -114,2 +114,3 @@ | ||
pattern, | ||
allowedPattern, | ||
value, | ||
@@ -125,4 +126,16 @@ label, | ||
root = host.shadowRoot, | ||
onChange = useCallback(e => host.dispatchEvent(new Event(e.type, { bubbles: e.bubbles })), []), | ||
onInput = useCallback(e => notifyProperty(host, 'value', e.target.value), []), | ||
onBeforeInput = useMemo(() => { | ||
if (allowedPattern == null) { | ||
return; | ||
} | ||
const regexp = new RegExp(allowedPattern, 'u'); | ||
return e => { | ||
if (!e.defaultPrevent && e.data && !regexp.test(e.data)) { | ||
e.preventDefault(); | ||
} | ||
onInput = useCallback(e => notifyProperty(host, 'value', e.target.value), []), | ||
}; | ||
}, [allowedPattern]), | ||
onFocus = useCallback(e => notifyProperty(host, 'focused', e.type === 'focus'), []), | ||
@@ -169,3 +182,4 @@ focus = useCallback(() => root.querySelector('input')?.focus(), []), | ||
.value=${ live(value ?? '') } autocomplete=${ ifDefined(autocomplete) } | ||
@input=${ onInput } @focus=${ onFocus } @blur=${ onFocus } | ||
@beforeinput=${ onBeforeInput } @input=${ onInput } | ||
@change=${ onChange } @focus=${ onFocus } @blur=${ onFocus } | ||
> | ||
@@ -185,2 +199,3 @@ ${ label ? html`<label for="input" part="label">${ label }</label>` : nothing } | ||
'pattern', | ||
'allowed-pattern', | ||
'readonly', | ||
@@ -187,0 +202,0 @@ 'disabled', |
{ | ||
"name": "@neovici/cosmoz-input", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A input web component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14070
259