Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Conditional statement to change the width of a info banner within a form

I currently have a form with dropdown. If the user clicks off the form dropdown and hasn’t filled out a field they are presented an error banner. Also on this dropdown if a user selects a certain field instead or an error banner presenting itself under the dropdown they receive an info banner.
My problem is that the error banner and info banners need to span different widths.
The error banner needs to span 256px and the info banner 624px and responsive.

My error banner is fine at the moment but i can only really hard code the width for the info banner which I don’;t think is a good solution.

Given the below code can I make a conditional statement that when the info banner is displayed the parent width would be extended? Here is the min code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const StyledDropdown = styled.div ({
maxWidth: 256,
})

export default function Form() {
 return (
  <StyledDropdown>
   <Validation forThe=(RequestType)
    <RequestTypeDropDown
     requestTypeResponse={requestTypeResponse}

          onChange={selectedOption => {

            setFieldValue(RequestType, selectedOption)

          }}

          selectedRequestType={values.requestType}

          selectedClient={values[SelectedClient]}

          bannerText={values.requestType?.infoText}

        />

      </Validation>

    </StyledDropdown>

Can I use a conditional with the bannertext that would say if infotext is displayed change width of StyledDropdown?

>Solution :

One solution is to set the style rule when referencing SyledDropdown.

export default function Form() {
 return (
  <StyledDropdown style={{maxWidth: values.requestType ? '624px' : '256px'}}>
    //...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading