Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search component button elements don't have "type" attribute #1014

Open
localhosted opened this issue Jan 7, 2025 · 0 comments
Open

Search component button elements don't have "type" attribute #1014

localhosted opened this issue Jan 7, 2025 · 0 comments

Comments

@localhosted
Copy link

localhosted commented Jan 7, 2025

Since the search buttons don't have a "type" attribute, it will submit any form the grid is a child of

I have to hack a listener to add the attribute


 const stackRef = useRef<HTMLDivElement>(null);

  const setButtonTypes = (element: HTMLElement) => {
    const buttons = element.querySelectorAll('button');
    buttons.forEach((button) => {
      if (button.getAttribute('type') !== 'button') {
        button.setAttribute('type', 'button');
      }
    });
  };
  useLayoutEffect(() => {
    const stackElement = stackRef.current;

    if (stackElement) {
      setButtonTypes(stackElement);

      const observer = new MutationObserver((mutationsList) => {
        for (const mutation of mutationsList) {
          if (mutation.type === 'childList') {
            mutation.addedNodes.forEach((node) => {
              if (node instanceof HTMLElement) {
                setButtonTypes(node);
              }
            });
          }
        }
      });

      observer.observe(stackElement, { childList: true, subtree: true });

      return () => {
        observer.disconnect();
      };
    }
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant