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

fix(menu): fix menu visibility based on props #4645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BogiKay
Copy link
Contributor

@BogiKay BogiKay commented Mar 3, 2025

Motivation

PR simplify and fix updateVisibility function in Menu component.

Related issue

#4631

Test plan

I tested changes using slightly changed example from the issue, which I'm attaching below and it's working fine

const ReproExample: React.FC<{ navigation: any }> = ({ navigation }) => {
  const [menuVisible, setMenuVisible] = useState(false);
  const [textValue, setTextValue] = useState('');
  const data = ['first', 'second', 'third'];

  useEffect(() => {
    console.log(menuVisible);
  }, [menuVisible]);

  return (
    <View>
      <Menu
        visible={menuVisible}
        onDismiss={() => setMenuVisible(false)}
        anchorPosition="bottom"
        children={getMenuItems(data)}
        anchor={
          <TextInput
            value={textValue}
            onChangeText={(newText: string) => {
              setTextValue(newText);
              if (menuVisible === true && newText === '') {
                setMenuVisible(false);
              } else if (menuVisible === false) {
                setMenuVisible(true);
              }
            }}
            onSubmitEditing={() => setMenuVisible(false)}
            autoComplete="address-line1"
            mode="outlined"
          ></TextInput>
        }
      ></Menu>
    </View>
  );
};

function getMenuItems(data: string[]): React.JSX.Element {
  return (
    <>
      {data.map((thing) => (
        <Menu.Item key={thing} title={thing}></Menu.Item>
      ))}
    </>
  );
}

@BogiKay BogiKay self-assigned this Mar 3, 2025
@BogiKay BogiKay added the Menu label Mar 3, 2025
@callstack-bot
Copy link

Hey @BogiKay, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

@gpurbia
Copy link

gpurbia commented Mar 12, 2025

When do you plan to merge this and release it?

Copy link

@mamtajuddinIncapsulate mamtajuddinIncapsulate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good lets merge

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

Successfully merging this pull request may close these issues.

4 participants