Skip to content

Commit

Permalink
add default id to checkbox and datepicker
Browse files Browse the repository at this point in the history
fixes #248
  • Loading branch information
jsebrech committed Aug 12, 2021
1 parent 070ca5e commit 9df3e08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed

- Checkbox no longer becomes disabled when no id is given (fixes [#248](https://github.com/digipolisantwerp/antwerp-ui_react/issues/248))
- Datepicker label selects datepicker when no id is given

## v6.0.2 - 2021-06-08

Expand Down
6 changes: 4 additions & 2 deletions packages/form/src/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Checkbox extends Component<Props> {
}
}

defaultId = 'aui-cb-' + Math.random().toString(36);

render() {
const {
id,
Expand All @@ -43,15 +45,15 @@ class Checkbox extends Component<Props> {
<div className="a-input__checkbox">
<input
type="checkbox"
id={id}
id={id || this.defaultId}
name={name}
onChange={this.handleChange}
aria-checked={this.props.checked}
checked={this.props.checked}
disabled={disabled}
{...this.props.handler}
/>
<InputLabel htmlFor={id}>{label}{requiredLabel}</InputLabel>
<InputLabel htmlFor={id || this.defaultId}>{label}{requiredLabel}</InputLabel>
</div>
</div>
)
Expand Down
6 changes: 4 additions & 2 deletions packages/form/src/Datepicker/Datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Datepicker extends Component<Props> {
disabled: false,
};

defaultId = 'aui-date-' + Math.random().toString(36);

componentDidMount() {
if (typeof window !== 'undefined') {
document.addEventListener('mousedown', this.handleClickOutside.bind(this));
Expand Down Expand Up @@ -226,12 +228,12 @@ class Datepicker extends Component<Props> {
);

return <div className={datepickerWrapperClass} ref={node => this.datepicker = node} data-qa={qa}>
{label && <InputLabel htmlFor={id}>{label}</InputLabel>}
{label && <InputLabel htmlFor={id || this.defaultId}>{label}</InputLabel>}
<div className="a-input__wrapper">
<TextField
mask={mask}
name={name}
id={id}
id={id || this.defaultId}
value={input}
required={required}
readOnly={readOnly}
Expand Down

0 comments on commit 9df3e08

Please sign in to comment.