HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/admin-modal/fields/FieldDropdown.js
import React, { Component } from 'react';
import Select from 'react-select';

export default class FieldDropdown extends Component {
    shouldComponentUpdate(nextProps) {
        return JSON.stringify(this.props.options) !== JSON.stringify(nextProps.options) || this.props.value !== nextProps.value || this.props.isDisabled !== nextProps.isDisabled;
    }

    render() {
        let selectedOption = false;
        const menuPortalTarget = 'undefined' !== typeof document ? document.body : null;

        if ( this.props.options ) {
            const allOptions = this.props.options.reduce((acc, cur) => {
                if ( cur.hasOwnProperty('options') ) {
                    acc = acc.concat( cur.options );
                } else {
                    acc.push(cur);
                }
        
                return acc;
            }, []);

            selectedOption = allOptions.find((option) => option.value === this.props.value);
        }

        const customProps = this.props.custom ? this.props.custom : {};

        return (
            <Select
                isDisabled={ this.props.isDisabled }
                options={this.props.options}
                value={selectedOption}
                placeholder={this.props.placeholder}
                menuPortalTarget={ menuPortalTarget }
                menuPosition="fixed"
                onChange={(option) => {
                    this.props.onChange(option.value);
                }}
                styles={{
                    control: (provided) => ({
                        ...provided,
                        backgroundColor: 'white',
                    }),
                    container: (provided) => ({
                        ...provided,
                        width: '100%',
                        maxWidth: this.props.width ? this.props.width : '100%',
                    }),
                    menuPortal: (provided) => ({
                        ...provided,
                        zIndex: 100001,
                    }),
                    menu: (provided) => ({
                        ...provided,
                        zIndex: 100001,
                    }),
                }}
                { ...customProps }
            />
        );
    }
}