Skip to content

Commit

Permalink
Merge pull request #55 from ltplabs/master
Browse files Browse the repository at this point in the history
Solve an issue where in some cases clicking on the menu would jump back to a different option due to the manual select.
  • Loading branch information
fgdvir authored Dec 13, 2023
2 parents d2efaf4 + 32f483a commit d3518b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion streamlit_option_menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d3518b2

Please sign in to comment.