Skip to content

Commit

Permalink
[TextControls] Add placeholderColor property
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 351648295
  • Loading branch information
andrewoverton authored and material-automation committed Jan 13, 2021
1 parent 6b4b029 commit 48808bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/TextControls/src/BaseTextAreas/MDCBaseTextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@ values are allowed.
*/
@property(nonatomic, strong, nullable) NSString *placeholder;

/**
The color of the placeholder. The default value is the color used by the placeholder in @c
UITextField.
*/
@property(nonatomic, strong, null_resettable) UIColor *placeholderColor;

@end
10 changes: 9 additions & 1 deletion components/TextControls/src/BaseTextAreas/MDCBaseTextArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#import "private/MDCBaseTextAreaLayout.h"
#import "private/MDCBaseTextAreaTextView.h"
#import "MDCBaseTextAreaDelegate.h"
#import "MDCTextControlLabelBehavior.h"
#import "MDCTextControlState.h"
#import "MaterialTextControlsPrivate+BaseStyle.h"
#import "MDCTextControlAssistiveLabelDrawPriority.h"
#import "MaterialTextControlsPrivate+Shared.h"

static char *const kKVOContextMDCBaseTextArea = "kKVOContextMDCBaseTextArea";
Expand Down Expand Up @@ -109,6 +112,7 @@ - (void)initializeProperties {
self.minimumNumberOfVisibleRows = kMDCBaseTextAreaDefaultMinimumNumberOfVisibleLines;
self.maximumNumberOfVisibleRows = kMDCBaseTextAreaDefaultMaximumNumberOfVisibleLines;
self.gradientManager = [[MDCTextControlGradientManager alloc] init];
self.placeholderColor = [self defaultPlaceholderColor];
}

- (void)setUpTapGesture {
Expand Down Expand Up @@ -418,7 +422,7 @@ - (NSAttributedString *)determineAttributedPlaceholder {
if ([self shouldPlaceholderBeVisible]) {
NSDictionary<NSAttributedStringKey, id> *attributes = @{
NSParagraphStyleAttributeName : [self defaultPlaceholderParagraphStyle],
NSForegroundColorAttributeName : [self defaultPlaceholderColor],
NSForegroundColorAttributeName : self.placeholderColor,
NSFontAttributeName : self.normalFont
};
return [[NSAttributedString alloc] initWithString:self.placeholder attributes:attributes];
Expand Down Expand Up @@ -529,6 +533,10 @@ - (void)setPlaceholder:(NSString *)placeholder {
[self setNeedsLayout];
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor {
_placeholderColor = placeholderColor ?: [self defaultPlaceholderColor];
}

#pragma mark MDCTextControl Protocol Accessors

- (void)setLeadingView:(UIView *)leadingView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ - (void)testTextAreaWithLabelAndPlaceholderWhileEditing {
[self validateTextArea:textArea];
}

- (void)testTextAreaWithLabelAndCustomColorPlaceholderWhileEditing {
// Given
MDCBaseTextArea *textArea = self.textArea;

// When
textArea.placeholderColor = [UIColor blueColor];
textArea.placeholder = @"This is a custom color placeholder.";
textArea.label.text = @"This is a floating label";
[textArea.textView becomeFirstResponder];

// Then
[self validateTextArea:textArea];
}

- (void)testTextAreaWithArabigLabelAndPlaceholderWhileEditingRTL {
// Given
MDCBaseTextArea *textArea = self.textArea;
Expand Down

0 comments on commit 48808bf

Please sign in to comment.