You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the opened issues and there are no duplicates
Describe the bug
When defining both HOVERED and PRESSED states for a button property using ControlStateValue, the PRESSED state is ignored if HOVERED is present. This appears to be due to a lack of state precedence handling, where the HOVERED state always takes precedence over PRESSED since the button is technically still being hovered while pressed.
On press: Stays at HOVERED color instead of changing to PRESSED color
On release while still hovering: Stays at HOVERED color
On mouse leave: Returns to DEFAULT color
To reproduce
run the repro code
Expected behavior
The button states should follow a clear precedence order with predictable transitions between states:
State Precedence (highest to lowest):
DISABLED/ERROR (if present)
PRESSED
HOVERED
DEFAULT
Screenshots / Videos
Capturescontrolstate-bug.mp4
Operating System
Windows
Operating system details
windows 11
Flet version
0.24.1
Regression
I'm not sure / I don't know
Suggestions
in the _wrap_attr_dict method of the Control class, since this is where Flet handles the ControlState dictionary conversion, we can process the state precedence:
classControl:
# ... etcdef_wrap_attr_dict(self, value: Optional[Union[Dict, Any]]) ->Optional[Dict]:
ifvalueisNoneorisinstance(value, Dict):
# If it's already a dictionary (state values), process for precedenceifisinstance(value, Dict):
returnself._process_state_dict(value)
returnvaluereturn {ControlState.DEFAULT: value}
def_process_state_dict(self, state_dict: Dict) ->Dict:
""" Process a state dictionary to ensure proper state precedence. Called internally by _wrap_attr_dict. """# If there's only one state, no need for precedence handlingiflen(state_dict) <=1:
returnstate_dict# Get the current active statesactive_states=set()
ifself.disabled:
active_states.add(ControlState.DISABLED)
ifself._get_attr("error", data_type="bool", def_value=False):
active_states.add(ControlState.ERROR)
ifself._get_attr("pressed", data_type="bool", def_value=False):
active_states.add(ControlState.PRESSED)
ifself._get_attr("hovered", data_type="bool", def_value=False):
active_states.add(ControlState.HOVERED)
# Return value based on priorityforstatein [
ControlState.DISABLED,
ControlState.ERROR,
ControlState.PRESSED,
ControlState.HOVERED,
ControlState.DEFAULT
]:
ifstateinactive_statesandstateinstate_dict:
return {ControlState.DEFAULT: state_dict[state]}
# Fallback to original default or first available valuereturn {ControlState.DEFAULT: state_dict.get(
ControlState.DEFAULT,
next(iter(state_dict.values()))
)}
Logs
Logs
Additional details
No response
The text was updated successfully, but these errors were encountered:
Duplicate Check
Describe the bug
When defining both
HOVERED
andPRESSED
states for a button property usingControlStateValue
, thePRESSED
state is ignored ifHOVERED
is present. This appears to be due to a lack of state precedence handling, where theHOVERED
state always takes precedence overPRESSED
since the button is technically still being hovered while pressed.Code sample
Code
When clicking the button:
To reproduce
Expected behavior
The button states should follow a clear precedence order with predictable transitions between states:
State Precedence (highest to lowest):
Screenshots / Videos
Captures
controlstate-bug.mp4
Operating System
Windows
Operating system details
windows 11
Flet version
0.24.1
Regression
I'm not sure / I don't know
Suggestions
in the
_wrap_attr_dict
method of theControl
class, since this is where Flet handles the ControlState dictionary conversion, we can process the state precedence:Logs
Logs
Additional details
No response
The text was updated successfully, but these errors were encountered: