1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import {Children} from 'react';
    
  11. 
    
  12. let didWarnSelectedSetOnOption = false;
    
  13. let didWarnInvalidChild = false;
    
  14. let didWarnInvalidInnerHTML = false;
    
  15. 
    
  16. /**
    
  17.  * Implements an <option> host component that warns when `selected` is set.
    
  18.  */
    
  19. 
    
  20. export function validateOptionProps(element: Element, props: Object) {
    
  21.   if (__DEV__) {
    
  22.     // If a value is not provided, then the children must be simple.
    
  23.     if (props.value == null) {
    
  24.       if (typeof props.children === 'object' && props.children !== null) {
    
  25.         Children.forEach(props.children, function (child) {
    
  26.           if (child == null) {
    
  27.             return;
    
  28.           }
    
  29.           if (typeof child === 'string' || typeof child === 'number') {
    
  30.             return;
    
  31.           }
    
  32.           if (!didWarnInvalidChild) {
    
  33.             didWarnInvalidChild = true;
    
  34.             console.error(
    
  35.               'Cannot infer the option value of complex children. ' +
    
  36.                 'Pass a `value` prop or use a plain string as children to <option>.',
    
  37.             );
    
  38.           }
    
  39.         });
    
  40.       } else if (props.dangerouslySetInnerHTML != null) {
    
  41.         if (!didWarnInvalidInnerHTML) {
    
  42.           didWarnInvalidInnerHTML = true;
    
  43.           console.error(
    
  44.             'Pass a `value` prop if you set dangerouslyInnerHTML so React knows ' +
    
  45.               'which value should be selected.',
    
  46.           );
    
  47.         }
    
  48.       }
    
  49.     }
    
  50. 
    
  51.     // TODO: Remove support for `selected` in <option>.
    
  52.     if (props.selected != null && !didWarnSelectedSetOnOption) {
    
  53.       console.error(
    
  54.         'Use the `defaultValue` or `value` props on <select> instead of ' +
    
  55.           'setting `selected` on <option>.',
    
  56.       );
    
  57.       didWarnSelectedSetOnOption = true;
    
  58.     }
    
  59.   }
    
  60. }