diff --git a/README.md b/README.md index 9903ec7..5c2a524 100755 --- a/README.md +++ b/README.md @@ -76,13 +76,16 @@ selected3 = option_menu(None, ["Home", "Upload", "Tasks", 'Settings'], ) # 4. Manual Item Selection -if st.session_state.get('switch_button', False): - st.session_state['menu_option'] = (st.session_state.get('menu_option',0) + 1) % 4 - manual_select = st.session_state['menu_option'] -else: - manual_select = None +option_list = ["Home", "Upload", "Tasks", 'Settings'] +manual_select = None +if st.session_state.get('menu_4', False): + option_list_option = st.session_state['switch_button'] + manual_select = option_list.index(option_list_option) # The manual select is the index of the list in the options + +if st.session_state.get('switch_button',False) and manual_select: # Check if the button was pressed and move it to the next option + manual_select = (manual_select + 1) % 4 -selected4 = option_menu(None, ["Home", "Upload", "Tasks", 'Settings'], +selected4 = option_menu(None, option_list, icons=['house', 'cloud-upload', "list-task", 'gear'], orientation="horizontal", manual_select=manual_select, key='menu_4') st.button(f"Move to Next {st.session_state.get('menu_option',1)}", key='switch_button') diff --git a/streamlit_option_menu/__init__.py b/streamlit_option_menu/__init__.py index a1fe8fd..cd2fb26 100755 --- a/streamlit_option_menu/__init__.py +++ b/streamlit_option_menu/__init__.py @@ -59,7 +59,7 @@ def option_menu(menu_title, options, default_index=0, menu_icon=None, icons=None else: register_callback(key, on_change, key) - if manual_select is not None and key is None: + if manual_select is not None: default_index = manual_select component_value = _component_func(options=options,