Skip to content

Commit

Permalink
feat(DropdownCellEditor.js): - supporting raw text in dropdown editor…
Browse files Browse the repository at this point in the history
… ( by passing acceptRawText )
  • Loading branch information
prakash1998 committed May 30, 2020
1 parent ff586b6 commit 5462a23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/CellEditContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class CellEditContainer extends React.Component {

getDropdownProps = ({ refKey = 'ref' }) => {
const choices = this.props.header && this.props.header.choices
const acceptRawText = (this.props.header && this.props.header.acceptRawText) || false
const virtualized = choices && choices.length > 10
const onKeyDown = virtualized ? this.dropdownInputKeyDown : this.dropdownKeyDown
return {
Expand All @@ -261,6 +262,8 @@ class CellEditContainer extends React.Component {
onKeyDown,
choices,
virtualized,
acceptRawText,
valueChanged: this.valueChanged,
'data-testid': 'cell-editing-element',
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/DropdownCellEditor/DropdownCellEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ class DropDownCellEditor extends React.Component {

state = { showSelection: true, justOpened: true }

inputValueChanged = _value => {
inputValueChanged = value => {
// console.log('value changed to ', value)
const { acceptRawText, valueChanged } = this.props
if (acceptRawText) {
valueChanged(value)
}
this.setState({ justOpened: false })
}

Expand Down Expand Up @@ -210,11 +214,11 @@ class DropDownCellEditor extends React.Component {
)

render() {
const { choices, value, onChange, virtualized, zIndex } = this.props
const { choices, value, onChange, virtualized, zIndex, acceptRawText } = this.props
// eslint-disable-next-line standard/object-curly-even-spacing
const { /* showSelection, */ justOpened } = this.state
const renderList = virtualized ? renderVirtualizedList : renderBasicList
const renderSelector = virtualized ? this.renderInput : this.renderComboBox
const renderSelector = virtualized || acceptRawText ? this.renderInput : this.renderComboBox

const selectedItem = R.find(c => value === c.value, choices)
const hilightedIndex = R.findIndex(c => value === c.value, choices)
Expand Down
3 changes: 2 additions & 1 deletion src/stories/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const unitDataFormatter = ({ value }) => unitMap[value] || value
/* prettier-ignore */
export const headers = [
dateCol({ ident: 'transDate', display: 'Trans-Date', width:120, isKey:true, }),
strCol({ ident: 'unitId', display: 'Unit', width:180, isKey:true, dataFormatter:unitDataFormatter,choices:unitChoices }),
strCol({ ident: 'unitId', display: 'Unit', width:180, isKey:true, dataFormatter:unitDataFormatter,choices:unitChoices
, acceptRawText : true , setInvalidMessage : ({value}) => !unitMap[value] && value !== 'prakash' && 'Please Enter Valid Data.' }),
intCol({ ident: 'he', display: 'HE', width: 40,isKey:true, numFormat:"0", }),
strCol({ ident: 'fixedGen', display: 'Fixed Gen' , ellipsis : true }),
numCol({ ident: 'emerMinOvr', display: 'Emer Min', width:120, alignment:'right', displayFormat: null }),
Expand Down

0 comments on commit 5462a23

Please sign in to comment.