Files
editor/src/components/InputMultiInput.tsx
Frank Elsinga 4f52df7c3b fix: Multi choice options style regression (#1174)
## Launch Checklist


This PR fixes the silliness with the `maputnik-multibutton` requiring
`maputnik-button` and `@extend` not working because not included in said
file.

Fixes https://github.com/maplibre/maputnik/issues/1044

| Before | After |
|--------|--------|
|
![image](https://github.com/user-attachments/assets/0f4cd7a3-0359-4d0f-aaca-b346739cb760)
|
![image](https://github.com/user-attachments/assets/8b8f4aa4-b672-4495-9454-864d756799cc)
|


This also fixes the same issue a few lines up where
`maputnik-delete-filter` refers to an not imprted `@extend`.


 - [x] Write tests for all new functionality.
 - [x] Add an entry to `CHANGELOG.md` under the `## main` section.
2025-05-04 07:39:48 +03:00

40 lines
1.1 KiB
TypeScript

import React from 'react'
import classnames from 'classnames'
export type InputMultiInputProps = {
name?: string
value: string
options: any[]
onChange(...args: unknown[]): unknown
'aria-label'?: string
};
export default class InputMultiInput extends React.Component<InputMultiInputProps> {
render() {
let options = this.props.options
if(options.length > 0 && !Array.isArray(options[0])) {
options = options.map(v => [v, v])
}
const selectedValue = this.props.value || options[0][0]
const radios = options.map(([val, label])=> {
return <label
key={val}
className={classnames("maputnik-button", "maputnik-radio-as-button", {"maputnik-button-selected": val === selectedValue})}
>
<input type="radio"
name={this.props.name}
onChange={_e => this.props.onChange(val)}
value={val}
checked={val === selectedValue}
/>
{label}
</label>
})
return <fieldset className="maputnik-multibutton" aria-label={this.props['aria-label']}>
{radios}
</fieldset>
}
}