[NUI] Add EnableMultiSelection to SelectGroup (#2116)
authorJaehyun Cho <29364140+jaehyun0cho@users.noreply.github.com>
Tue, 10 Nov 2020 11:15:02 +0000 (20:15 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 11 Nov 2020 02:33:04 +0000 (11:33 +0900)
To support selecting multiple SelectButtons in SelectGroup,
bool EnableMultiSelection is added to SelectGroup.

By adding EnableMultiSelection in SelectGroup, RadioButtonGroup does not
need to implement its logic to prevent selecting multiple RadioButtons.

Co-authored-by: Jaehyun Cho <jae_hyun.cho@samsung.com>
Co-authored-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/RadioButtonGroup.cs
src/Tizen.NUI.Components/Controls/SelectGroup.cs

index 18a031d..a028465 100755 (executable)
@@ -42,6 +42,7 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         public RadioButtonGroup() : base()
         {
+            EnableMultiSelection = false;
         }
 
         /// <summary>
@@ -84,30 +85,5 @@ namespace Tizen.NUI.Components
             base.RemoveSelection(radio);
             radio.ItemGroup = null;
         }
-
-        /// <summary>
-        /// Handle user's select action. Turn on check state of selected RadioButton,
-        /// and turn out check state of other RadioButtons in RadioButtonGroup
-        /// </summary>
-        /// <param name="selection">The selection selected by user</param>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void SelectionHandler(SelectButton selection)
-        {
-            RadioButton radio = selection as RadioButton;
-            if (!ItemGroup.Contains(radio))
-            {
-                return;
-            }
-
-            foreach (RadioButton btn in ItemGroup)
-            {
-                if (btn != null && btn != radio && btn.IsEnabled == true)
-                {
-                    btn.IsSelected = false;
-                }
-            }
-        }
     }
 }
index 9b39097..01c638d 100755 (executable)
@@ -70,6 +70,12 @@ namespace Tizen.NUI.Components
         public int SelectedIndex => selectedIndex;
 
         /// <summary>
+        /// EnableMultiSelection is used to indicate if SelectGroup can select multiple SelectButtons.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool EnableMultiSelection { get; set; } = true;
+
+        /// <summary>
         /// Construct SelectionGroup
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
@@ -142,7 +148,7 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Overrides this method if want to handle behavior after pressing return key by user.
+        /// Called when the state of Selected is changed.
         /// </summary>
         /// <param name="selection">The selection selected by user</param>
         /// <since_tizen> 6 </since_tizen>
@@ -160,6 +166,18 @@ namespace Tizen.NUI.Components
                 if (args.IsSelected == true)
                 {
                     selectedIndex = selection.Index;
+
+                    if (EnableMultiSelection == false)
+                    {
+                        foreach (SelectButton btn in ItemGroup)
+                        {
+                            if ((btn != null) && (btn != selection) && (btn.IsEnabled == true) && (btn.IsSelected == true))
+                            {
+                                btn.IsSelected = false;
+                            }
+                        }
+                    }
+
                     SelectionHandler(selection);
                 }
             }