Sha256: 7ef9272af3dc6857107b90f17d33cd101049cf9bd6831c6fafbd2f00cda297f7

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

import React, { useState } from 'react';
import { FormGroup, Select, SelectOption } from '@patternfly/react-core';
import PropTypes from 'prop-types';

export const SelectField = ({
  label,
  fieldId,
  options,
  value,
  setValue,
  ...props
}) => {
  const onSelect = (event, selection) => {
    setValue(selection);
    setIsOpen(false);
  };
  const [isOpen, setIsOpen] = useState(false);
  return (
    <FormGroup label={label} fieldId={fieldId}>
      <Select
        selections={value}
        onSelect={onSelect}
        onToggle={setIsOpen}
        isOpen={isOpen}
        className="without_select2"
        maxHeight="45vh"
        menuAppendTo={() => document.body}
        {...props}
      >
        {options.map((option, index) => (
          <SelectOption key={index} value={option} />
        ))}
      </Select>
    </FormGroup>
  );
};
SelectField.propTypes = {
  label: PropTypes.string.isRequired,
  fieldId: PropTypes.string.isRequired,
  options: PropTypes.array,
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  setValue: PropTypes.func.isRequired,
};

SelectField.defaultProps = {
  options: [],
  value: null,
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_remote_execution-4.5.1 webpack/JobWizard/steps/form/SelectField.js
foreman_remote_execution-4.6.0 webpack/JobWizard/steps/form/SelectField.js
foreman_remote_execution-4.5.0 webpack/JobWizard/steps/form/SelectField.js