How to use @react-md/wia-aria - 5 common examples

To help you get started, we’ve selected a few @react-md/wia-aria examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mlaursen / react-md / packages / states / src / withStates.tsx View on Github external
/>
      );
    } else if (!disablePressedFallback) {
      // if the ripple effect was disabled and the default pressed state interactions were
      // also not disabled, we can hook into it there
      const { pressed, eventHandlers } = usePressedStates(providedProps);
      handlers = eventHandlers;
      className = cn(className, {
        "rmd-states--pressed": pressed,
      });
    }

    if (props.id) {
      // if the element is "valid" and has an id, we can also start the keyboard focus only
      // states for the element by merging the class name
      className = cn(className, useKeyboardFocusedClassName(props.id));
    } else if (process.env.NODE_ENV !== "production") {
      console.error(
        "Found a component that does not have an `id` prop, but is wrapped `withStates`. " +
          "This component will be unable to have keyboard focus states applied until this is fixed."
      );
      console.error(new Error().stack);
    }

    // TODO: Look into a better way of fixing color pollution and adding ripples to the component.
    // The problem with this current approach is that if the composed component wraps the children
    // in other components/elements for styling, the ripples and color pollution fixes will not
    // work as expected and positioning will be wrong. The current workaround is to create another
    // wrapper for the "custom" component children and do the wrapping before passing to the WithStates
    // hoc. ListItem is a good example of this. Also has problems with Tooltips :/
    if (preventColorPollution) {
      // note that the `ripplesContainer` is NOT added to the color pollution fix children. if the
github mlaursen / react-md / packages / states / src / hooks.tsx View on Github external
timeout={rippleTimeout}
        classNames={rippleClassNames}
      />
    );
  } else if (!disablePressedFallback) {
    // if the ripple effect was disabled and the default pressed state interactions were
    // also not disabled, we can hook into it there
    const { pressed, handlers: h } = usePressedStates(options);
    handlers = h;
    className = cn(className, { "rmd-states--pressed": pressed });
  }

  if (id) {
    // if the element is "valid" and has an id, we can also start the keyboard focus only
    // states for the element by merging the class name
    className = cn(className, useKeyboardFocusedClassName(id));
  }

  // "polyfill" the keyboard click events for elements that are supposed to behave like clickable
  // elements but really aren't. this will make sure to merge existing onKeyDown behaviors from
  // the ripple/pressed effects (if any) or the onKeyDown behavior from props
  if (enableKeyboardClick) {
    handlers = handlers || options.handlers || {};
    const { onKeyDown } = handlers;
    handlers.onKeyDown = (event: React.KeyboardEvent) => {
      if (onKeyDown) {
        onKeyDown(event);
      }

      if (!disableSpacebarClick && event.key === " ") {
        // need to prevent default behavior of screen scrolling
        event.preventDefault();
github mlaursen / react-md / packages / examples / src / SheetDemo.tsx View on Github external
const handleKeyDown = (position: SheetPosition) => (
    event: React.KeyboardEvent
  ) => {
    const { key } = event;
    if (key === "ArrowUp") {
      event.preventDefault();
      show(position, false)(event);
    } else if (key === "ArrowDown") {
      event.preventDefault();
      show(position)(event);
    }
  };

  const hide = () => setVisible(false);
  const toggle = () => setVisible(prevVisible => !prevVisible);
  useScrollLock(visible);

  // const { containerProps, setActiveId } = useActiveDescendantState({
  //   // search: true,
  //   defaultActiveId: "",
  //   // incrementKeys: ["ArrowDown"],
  //   // decrementKeys: ["ArrowUp"],
  //   // jumpToFirstKeys: ["Home"],
  //   // jumpToLastKeys: ["End"],
  //   onKeyDown: event => {
  //     if (event.key === "Tab" || event.key === "Escape") {
  //       event.stopPropagation();
  //       hide();
  //     }
  //   },
  // });
github mlaursen / react-md / packages / examples / src / components / menus / MenuButton.tsx View on Github external
> = allProps => {
  const { theme: t, themeType, buttonType, className, ...props } = allProps;
  return (
    
  );
};
github mlaursen / react-md / packages / examples / src / components / menus / MenuItem.tsx View on Github external
const MenuItem: FunctionComponent = ({
  className,
  ...props
}) => {
  return (
    
  );
};

@react-md/wia-aria

A package for determining which element on the page is the current keyboard focus/selection.

MIT
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis