Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Custom renderer for debug info #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions lib/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class Autocomplete extends React.Component {
*/
open: PropTypes.bool,
debug: PropTypes.bool,
/**
* Arguments: `renderer: Function`
* Custom renderer for debug info
*/
renderDebug: PropTypes.func,
}

static defaultProps = {
Expand Down Expand Up @@ -188,6 +193,11 @@ class Autocomplete extends React.Component {
autoHighlight: true,
selectOnBlur: false,
onMenuVisibilityChange() {},
renderDebug: function (debugStates) {
return <pre style={{ marginLeft: 300 }}>
{JSON.stringify(debugStates.slice(Math.max(0, debugStates.length - 5), debugStates.length), null, 2)}
</pre>
}
}

constructor(props) {
Expand Down Expand Up @@ -568,7 +578,7 @@ class Autocomplete extends React.Component {
})
}

const { inputProps } = this.props
const { inputProps, renderDebug } = this.props
const open = this.isOpen()
return (
<div style={{ ...this.props.wrapperStyle }} {...this.props.wrapperProps}>
Expand All @@ -587,11 +597,7 @@ class Autocomplete extends React.Component {
value: this.props.value,
})}
{open && this.renderMenu()}
{this.props.debug && (
<pre style={{ marginLeft: 300 }}>
{JSON.stringify(this._debugStates.slice(Math.max(0, this._debugStates.length - 5), this._debugStates.length), null, 2)}
</pre>
)}
{this.props.debug && renderDebug ? renderDebug(this._debugStates) : null}
</div>
)
}
Expand Down