Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken react select styling for large values #4812

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export const DraftDocumentTypesFeatureFlagOn = {
rsin: '111111111',
domain: 'TEST',
},
iotSubmissionReport: 'A rather long draft description',
iotSubmissionReport: 'Document type 4 with a rather long draft description',
iotSubmissionCsv: 'Not-found documenttype',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useField, useFormikContext} from 'formik';
import PropTypes from 'prop-types';
import {useContext, useEffect} from 'react';
import {FormattedMessage, useIntl} from 'react-intl';
import {components} from 'react-select';
import {useAsync, usePrevious} from 'react-use';

import {FeatureFlagsContext} from 'components/admin/form_design/Context';
Expand Down Expand Up @@ -42,28 +43,36 @@ const getDocumentTypes = async (apiGroupID, catalogueUrl) => {
const documentTypes = response.data.sort((a, b) => a.omschrijving.localeCompare(b.omschrijving));
return documentTypes.map(({omschrijving, isPublished}) => ({
value: omschrijving,
label: (
label: omschrijving,
isPublished: isPublished,
}));
};

// Components

const DocumentTypeSelectOption = props => {
const {isPublished, label} = props.data;
return (
<components.Option {...props}>
<span
className={classNames('catalogi-type-option', {
'catalogi-type-option--draft': !isPublished,
})}
>
<FormattedMessage
description="Document type option label"
defaultMessage={`{omschrijving} {isPublished, select, false {<draft>(not published)</draft>} other {}}`}
defaultMessage={`{label} {isPublished, select, false {<draft>(not published)</draft>} other {}}`}
values={{
omschrijving,
label,
isPublished,
draft: chunks => <span className="catalogi-type-option__draft-suffix">{chunks}</span>,
}}
/>
</span>
),
}));
</components.Option>
);
};

// Components

const DocumentType = ({name, label, loading, options, isDisabled, helpText}) => {
const intl = useIntl();
const [{value}, , fieldHelpers] = useField(name);
Expand Down Expand Up @@ -91,6 +100,7 @@ const DocumentType = ({name, label, loading, options, isDisabled, helpText}) =>
setValue(selectedOption ? selectedOption.value : undefined);
}}
isClearable
components={{Option: DocumentTypeSelectOption}}
/>
{showWarning && (
<WarningIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const DOCUMENT_TYPES = {
},
{
url: 'https://example.com/catalogi/api/v1/iot/13',
omschrijving: 'A rather long draft description',
omschrijving: 'Document type 4 with a rather long draft description',
catalogusLabel: 'TEST (111111111)',
isPublished: false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import classNames from 'classnames';
import {useField, useFormikContext} from 'formik';
import PropTypes from 'prop-types';
import React from 'react';
import {FormattedMessage} from 'react-intl';
import {components} from 'react-select';
import useAsync from 'react-use/esm/useAsync';

import Field from 'components/admin/forms/Field';
Expand All @@ -22,24 +24,34 @@ const getAvailableCaseTypes = async (apiGroupID, catalogueUrl) => {
const caseTypes = response.data.sort((a, b) => a.description.localeCompare(b.description));
return caseTypes.map(({identification, description, isPublished}) => ({
value: identification,
label: (
label: description,
isPublished: isPublished,
}));
};

// Components

const CaseTypeSelectOption = props => {
const {isPublished, label} = props.data;
return (
<components.Option {...props}>
<span
className={classNames('catalogi-type-option', {
'catalogi-type-option--draft': !isPublished,
})}
>
<FormattedMessage
description="Case type option label"
defaultMessage={`{description} {isPublished, select, false {<draft>(not published)</draft>} other {}}`}
defaultMessage={`{label} {isPublished, select, false {<draft>(not published)</draft>} other {}}`}
values={{
description,
label,
isPublished,
draft: chunks => <span className="catalogi-type-option__draft-suffix">{chunks}</span>,
}}
/>
</span>
),
}));
</components.Option>
);
};

const CaseTypeSelect = ({catalogueUrl = ''}) => {
Expand Down Expand Up @@ -88,6 +100,7 @@ const CaseTypeSelect = ({catalogueUrl = ''}) => {
// TODO: make required once legacy config is dropped
required={false}
isClearable
components={{Option: CaseTypeSelectOption}}
onChange={selectedOption => {
setValue(selectedOption ? selectedOption.value : undefined);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const CASE_TYPES = {
description: 'Draft case type',
isPublished: false,
},
{
identification: 'ZT23',
description: 'Published case type with a rather long description',
isPublished: true,
},
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@

@include bem.element('draft-suffix') {
color: var(--body-quiet-color);

// only display the suffix in the dropdown
@at-root .admin-react-select__value-container & {
display: none;
}
}
}
1 change: 1 addition & 0 deletions src/openforms/scss/vendor/_react-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
100%,
var(--of-admin-select-max-inline-size)
);
max-inline-size: var(--of-admin-select-max-inline-size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to do this in more places in other projects and now I no longer understand how clamp works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i also dont fully understand why the max-inline-size was needed.. Maybe because a child element was growing, instead of the .admin-react-select. So that the max-inline-size prevent all growth?

I think the clamp just allows the parent to grow between a min and max value, but it doesn't work fully for flexbox child elements? That they don't respect the set value, and grow beyond? The .admin-react-select is used in a flex-wrap environment, which might also complicate things..

But I haven't checked/investigated it so deeply..

}
Loading