Skip to content

Commit

Permalink
fix(textbox): [MacOS] Allow <TextBox> to appear on multi-lines when n…
Browse files Browse the repository at this point in the history
…ot focused.
  • Loading branch information
carldebilly committed Feb 9, 2021
1 parent 01a38fa commit 8af85fd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
@@ -1,4 +1,4 @@
<UserControl
<Page
x:Class="Uno.UI.Samples.Content.UITests.TextBoxControl.Input_Multiline"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -12,15 +12,37 @@
d:DesignHeight="300"
d:DesignWidth="400">

<StackPanel>
<TextBox Header="Enter data:"
Height="120"
<StackPanel Spacing="6">
<TextBlock>TextWrapping="Wrap" / AcceptsReturn="True"</TextBlock>
<TextBox Header="Header Text:"
MinHeight="120"
MaxWidth="300"
Text="{Binding [MyInput], Mode=TwoWay}"
Text="{Binding MyInput, Mode=TwoWay}"
TextWrapping="Wrap"
AcceptsReturn="True" />
<TextBlock>TextWrapping="WrapWholeWords" / AcceptsReturn="True"</TextBlock>
<TextBox Header="Header Text:"
MinHeight="120"
MaxWidth="300"
Text="{Binding MyInput, Mode=TwoWay}"
TextWrapping="WrapWholeWords"
AcceptsReturn="True" />
<TextBlock>TextWrapping="Wrap" / AcceptsReturn="False"</TextBlock>
<TextBox Header="Header Text:"
MinHeight="120"
MaxWidth="300"
Text="{Binding MyInput, Mode=TwoWay}"
TextWrapping="Wrap"
AcceptsReturn="False" />
<TextBlock>TextWrapping="WrapWholeWords" / AcceptsReturn="False"</TextBlock>
<TextBox Header="Header Text:"
MinHeight="120"
MaxWidth="300"
Text="{Binding MyInput, Mode=TwoWay}"
TextWrapping="WrapWholeWords"
AcceptsReturn="False" />
<TextBlock Text="Result :" />
<TextBlock Text="{Binding [Result]}" />
<TextBlock Text="{Binding Result}" />
</StackPanel>

</UserControl>
</Page>
Expand Up @@ -4,8 +4,8 @@

namespace Uno.UI.Samples.Content.UITests.TextBoxControl
{
[SampleControlInfo("TextBox", "Input_Multiline", typeof(TextBoxViewModel))]
public sealed partial class Input_Multiline : UserControl
[Sample("TextBox", ViewModelType = typeof(TextBoxViewModel))]
public sealed partial class Input_Multiline : Page
{
public Input_Multiline()
{
Expand Down
14 changes: 8 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs
Expand Up @@ -43,15 +43,11 @@ protected TextBox(bool isPassword)
else
{
_textBoxView.BecomeFirstResponder();

}
}
}

public override bool BecomeFirstResponder()
{
return (_textBoxView?.BecomeFirstResponder()).GetValueOrDefault(false);
}
public override bool BecomeFirstResponder() => _textBoxView?.BecomeFirstResponder() ?? false;

partial void OnAcceptsReturnChangedPartial(DependencyPropertyChangedEventArgs e)
{
Expand Down Expand Up @@ -84,7 +80,13 @@ private void UpdateTextBoxView()
}
else
{
_textBoxView = new TextBoxView(this) { UsesSingleLineMode = AcceptsReturn || TextWrapping != TextWrapping.NoWrap };
var textWrapping = TextWrapping;
var usesSingleLineMode = !(AcceptsReturn || textWrapping != TextWrapping.NoWrap);
_textBoxView = new TextBoxView(this)
{
UsesSingleLineMode = usesSingleLineMode,
LineBreakMode = textWrapping == TextWrapping.WrapWholeWords ? NSLineBreakMode.ByWordWrapping : NSLineBreakMode.CharWrapping,
};
}

_contentElement.Content = _textBoxView;
Expand Down

0 comments on commit 8af85fd

Please sign in to comment.