<commit_before><commit_msg>moved checking for a11y tags when a button is an input button into its own utility function #227<commit_after>import React from 'react';
import warning from 'warning';

export const HtmlForTagName = 'htmlFor';
export const InputTypeName = 'input';
export const a11yButtonTagsToTest = [HtmlForTagName, 'aria-labelledby', 'aria-describedby'];

/*
 * Check if the children have an input node.
 * If there is an input node, check that it meets the a11y tag requirements :
 * Must have all of the tags listed in the a11yTagsToTest array.
 * If any of the tags are missing a warning will be output.
 * Input : componentId - the ID of the component being checked or null.
 *         children    - the child nodes of the component being checked or null.
 *         excludeTag  - any tag of which the tests should be expcitly ignored.
 */
export function checkChildrenInputWitha11y(componentId, children, excludeTag) {
  if (children !== null) {
    // tags to test for in the children
    const elementId = componentId !== null ? `Element [id: ${componentId}]:` : '';
    const identity = `Material-UI: ${elementId}`;

    React.Children.forEach(children, (child) => {
      if (child !== null) {
        if (child.type === InputTypeName) {
          for (let index = 0; index < a11yButtonTagsToTest.length; index++) {
            const tagToTest = a11yButtonTagsToTest[index];
            if (((tagToTest !== excludeTag)) && (!child.props.hasOwnProperty(tagToTest))) {
              const message = `${identity} Buttons with a child <input> element should should contain the property '${tagToTest}' inside the input tag.`;
              warning(false, message);
            }
          }
        }
      }
    });
  }
};
{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.010344827586206896, 'mean_word_length': 3.106132075471698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5654236', 'n_tokens_mistral': 484, 'n_tokens_neox': 474, 'n_words': 186}