Enhance FilterSidebar with dynamic field select sizing
Some checks reported errors
farmcontrol/farmcontrol-ui/pipeline/head Something is wrong with the build of this commit

- Introduced a new FieldSelectLabel component to dynamically size select fields based on the longest label, improving layout consistency.
- Updated FilterSidebar to utilize the FieldSelectLabel for better visual alignment of select options.
- Adjusted CSS styles for the filter sidebar field selects to ensure proper width handling.
This commit is contained in:
Tom Butcher 2026-08-11 01:03:40 +01:00
parent ca74cce3b9
commit 72c5ee1b91
2 changed files with 43 additions and 1 deletions

View File

@ -1131,3 +1131,11 @@ span.ant-skeleton-input.ant-skeleton-input-sm.text-skeleton {
top: -16px !important;
bottom: -24px !important;
}
/* Size FilterSidebar field selects to the longest label (via labelRender sizer). */
.filter-sidebar-field-select.ant-select {
width: max-content;
}
.filter-sidebar-field-select .ant-select-selector {
width: max-content !important;
}

View File

@ -11,6 +11,36 @@ import {
import MissingPlaceholder from './MissingPlaceholder'
import BinIcon from '../../Icons/BinIcon'
const hiddenSizerStyle = {
gridArea: '1 / 1',
visibility: 'hidden',
whiteSpace: 'nowrap'
}
const FieldSelectLabel = ({ label, options }) => (
<span style={{ display: 'inline-grid' }}>
<span aria-hidden style={hiddenSizerStyle}>
Field
</span>
{options.map((option) => (
<span key={option.value} aria-hidden style={hiddenSizerStyle}>
{option.label}
</span>
))}
<span style={{ gridArea: '1 / 1', whiteSpace: 'nowrap' }}>{label}</span>
</span>
)
FieldSelectLabel.propTypes = {
label: PropTypes.node,
options: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.node,
value: PropTypes.string
})
).isRequired
}
const FilterSidebar = ({
type,
filter = {},
@ -169,8 +199,12 @@ const FilterSidebar = ({
value={row.field || undefined}
onChange={(v) => changeField(row.field, v)}
options={availableOptions(row.field)}
style={{ minWidth: 80 }}
allowClear={false}
labelRender={({ label }) => (
<FieldSelectLabel label={label} options={fieldOptions} />
)}
style={{ flexShrink: 0 }}
classNames={{ root: 'filter-sidebar-field-select' }}
/>
<FilterInput
placeholder='Value'