Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payload-react",
"version": "1.2.0",
"version": "1.2.1",
"description": "A simple React wrapper around Payload.js. See https://docs.payload.co for more information.",
"main": "dist/payload-react.js",
"module": "dist/payload-react.js",
Expand Down
17 changes: 15 additions & 2 deletions src/payload-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const inputEventsMap = {
valid: 'onValid',
focus: 'onFocus',
blur: 'onBlur',
changed: 'onChanged',
change: 'onChange',
}

const processingFormEventsMap = {
Expand Down Expand Up @@ -78,7 +78,15 @@ export class PayloadInput extends React.Component {
this.inputRef = React.createRef()
}

isSensitiveField() {
return sensitiveFields[
this.props.attr || this._pl_input || this.props['pl-input']
]
}

componentDidMount() {
if (!this.isSensitiveField()) return

Object.entries(inputEventsMap).forEach(([key, value]) => {
if (value in this.props)
this.context.addListener(key, this.inputRef, (...args) =>
Expand All @@ -88,13 +96,18 @@ export class PayloadInput extends React.Component {
}

componentWillUnmount() {
if (!this.isSensitiveField()) return

Object.entries(inputEventsMap).forEach(([key, value]) => {
if (value in this.props) this.context.removeListener(key, this.inputRef)
})
}

render() {
const attrs = getPropAttrs(this.props, Object.values(inputEventsMap))
const attrs = getPropAttrs(
this.props,
this.isSensitiveField() ? Object.values(inputEventsMap) : []
)

if (this._pl_input) attrs['pl-input'] = this._pl_input

Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/payload-react.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ exports[`PayloadReact expect state to be updated with Payload when window.Payloa
[Function],
],
[
"changed",
"change",
[Function],
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/payload-react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('PayloadReact', () => {
onValid: jest.fn(),
onFocus: jest.fn(),
onBlur: jest.fn(),
onChanged: jest.fn(),
onChange: jest.fn(),
}

const form = mount(
Expand Down