Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/droid fix caret #107

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
/umd
npm-debug.log*
package-lock.json
.idea/misc.xml
.idea/react-maskedinput-privacy.iml
.idea/modules.xml
.idea/workspace.xml
.idea/vcs.xml
129 changes: 2 additions & 127 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,134 +1,9 @@
# `MaskedInput`
# `MaskedInputPrivacy`

A [React](http://facebook.github.io/react/) component for `<input>` masking, built on top of [inputmask-core](https://github.com/insin/inputmask-core).

![This project has never been used by its author, other than while making it.](https://img.shields.io/badge/author--usage-never-red.png "This project has never been used by its author, other than while making it")

## [Live Demo](http://insin.github.io/react-maskedinput/)

## Install

### npm

`MaskedInput` can be used on the server, or bundled for the client using an npm-compatible packaging system such as [Browserify](http://browserify.org/) or [webpack](http://webpack.github.io/).

```
npm install react-maskedinput --save
```

### Browser bundle

The browser bundle exposes a global `MaskedInput` variable and expects to find a global `React` (>= 0.14.0) variable to work with.

* [react-maskedinput.js](https://unpkg.com/react-maskedinput/umd/react-maskedinput.js) (development version)
* [react-maskedinput.min.js](https://unpkg.com/react-maskedinput/umd/react-maskedinput.min.js) (compressed production version)

## Usage

Give `MaskedInput` a [`mask`](#mask-string) and an `onChange` callback:

```javascript
var React = require('react')
var MaskedInput = require('react-maskedinput')

var CreditCardDetails = React.createClass({
state: {
card: '',
expiry: '',
ccv: ''
},

_onChange(e) {
var stateChange = {}
stateChange[e.target.name] = e.target.value
this.setState(stateChange)
},

render() {
return <div className="CreditCardDetails">
<label>
Card Number:{' '}
<MaskedInput mask="1111 1111 1111 1111" name="card" size="20" onChange={this._onChange}/>
</label>
<label>
Expiry Date:{' '}
<MaskedInput mask="11/1111" name="expiry" placeholder="mm/yyyy" onChange={this._onChange}/>
</label>
<label>
CCV:{' '}
<MaskedInput mask="111" name="ccv" onChange={this._onChange}/>
</label>
</div>
}
})
```

Create some wrapper components if you have a masking configuration which will be reused:

```javascript
var CustomInput = React.createClass({
render() {
return <MaskedInput
mask="1111-WW-11"
placeholder="1234-WW-12"
size="11"
{...this.props}
formatCharacters={{
'W': {
validate(char) { return /\w/.test(char ) },
transform(char) { return char.toUpperCase() }
}
}
}/>
}
})
```

## Props

### `mask` : `string`

The masking pattern to be applied to the `<input>`.

See the [inputmask-core docs](https://github.com/insin/inputmask-core#pattern) for supported formatting characters.

### `onChange` : `(event: SyntheticEvent) => any`

A callback which will be called any time the mask's value changes.

This will be passed a `SyntheticEvent` with the input accessible via `event.target` as usual.

**Note:** this component currently calls `onChange` directly, it does not generate an `onChange` event which will bubble up like a regular `<input>` component, so you *must* pass an `onChange` if you want to get a value back out.

### `formatCharacters`: `Object`

Customised format character definitions for use in the pattern.

See the [inputmask-core docs](https://github.com/insin/inputmask-core#formatcharacters) for details of the structure of this object.

### `placeholderChar`: `string`

Customised placeholder character used to fill in editable parts of the pattern.

See the [inputmask-core docs](https://github.com/insin/inputmask-core#placeholderchar--string) for details.

### `value` : `string`

A default value for the mask.

### `placeholder` : `string`

A default `placeholder` will be generated from the mask's pattern, but you can pass a `placeholder` prop to provide your own.

### `size` : `number | string`

By default, the rendered `<input>`'s `size` will be the length of the pattern, but you can pass a `size` prop to override this.

### Other props

Any other props passed in will be passed as props to the rendered `<input>`, except for the following, which are managed by the component:

* `maxLength` - will always be equal to the pattern's `.length`
* `onKeyDown`, `onKeyPress` & `onPaste` - will each trigger a call to `onChange` when necessary
In progress

## MIT Licensed
1 change: 1 addition & 0 deletions nwb.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function(build) {
// demo build.
config.webpack = {
extra: {
devtool: 'source-map',
node: {
process: false
}
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-maskedinput",
"version": "4.0.0",
"name": "react-maskedinput-privacy",
"version": "4.0.1",
"description": "Masked <input/> React component",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -31,12 +31,11 @@
"react": "15.x",
"react-dom": "15.x"
},
"author": "Jonny Buchanan <[email protected]>",
"homepage": "https://github.com/insin/react-maskedinput",
"author": "Greg Hawk <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/insin/react-maskedinput.git"
"url": "http://github.com/greghawk/react-maskedinput-privacy.git"
},
"keywords": [
"react",
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class MaskedInput extends React.Component {

_updateMaskSelection() {
this.mask.selection = getSelection(this.input)
setTimeout(function() {
this.input.setSelectionRange(this.mask.selection.start, this.mask.selection.end);
}.bind(this), 1);
}

_updateInputSelection() {
Expand Down