Skip to content

Commit

Permalink
Add QuestionEraseValues component for checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 9, 2025
1 parent 39c32c3 commit ccd3cd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'
import PropTypes from 'prop-types'

const QuestionEraseValues = ({ values, disabled, deleteValue }) => {
const handleEraseValue = () => {
values.forEach((value) => deleteValue(value))
}

return !disabled && (
<button type="button" className="btn btn-link btn-erase-value" onClick={handleEraseValue}
title={gettext('Erase input')}>
<i className="fa fa-eraser fa-btn"></i>
</button>
)
}

QuestionEraseValues.propTypes = {
values: PropTypes.array.isRequired,
disabled: PropTypes.bool.isRequired,
deleteValue: PropTypes.func.isRequired
}

export default QuestionEraseValues
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { maxBy } from 'lodash'
import { gatherOptions } from '../../../utils/options'

import QuestionCopyValues from '../question/QuestionCopyValues'
import QuestionEraseValues from '../question/QuestionEraseValues'
import QuestionError from '../question/QuestionError'
import QuestionSuccess from '../question/QuestionSuccess'

Expand Down Expand Up @@ -71,6 +72,11 @@ const CheckboxWidget = ({ question, sets, values, siblings, currentSet, disabled
</div>
<div className="buttons">
<QuestionSuccess value={{ success }} />
<QuestionEraseValues
values={values}
disabled={disabled}
deleteValue={deleteValue}
/>
<QuestionCopyValues
question={question}
sets={sets}
Expand Down

0 comments on commit ccd3cd8

Please sign in to comment.