Source: Material.io

Create an Adaptive Sketch Symbol for Material Design’s Outlined Text Field

In Helping Designers Adhere to a Design System with Sketch, I showed an adaptive symbol for Material Design’s outlined text field that I created. The symbol adapts to the length of the override text for the label and input.

By the end of this tutorial, you’ll will have created an adaptable and resizable outlined input box.
This article is in response to those asking how I made this symbol. Rather than only explaining how to make it, I attempt to explain why it works; step by step.
Download the Sketch file

Google’s Technique vs this technique

Google released its awesome Sketch Theme Editor plugin for creating your own themed Material symbols. However, is usefulness are limited by how it’s made.

Google’s symbol from its Sketch Theme editor doesn’t adapt to the override text.

At the time of this writing, all text are symbols. This prevents neighboring elements from moving as the override text length changes. The result is only four characters can be entered in label and the cursor also doesn’t move with the override text. A shape, using the predefined surface color, is placed above of the top border to make it look like a cutout for the label. This only works if the background uses the same surface color as the overlaying shape; otherwise, it’s visible.

In contrast, the technique described in this article shows how to create the same symbol but is truly adaptable to override text and has an actual cutout of the label, allowing it to be placed on any background. These techniques can be applied to creating a multitude of adaptable symbols.


Step 1: Getting set up

  1. Create an a symbol with the dimensions 328x56
  2. Give it a meaningful label, like Outline Text Field Active

Step 2: Create the border

The border is not a closed shape. To accomplish this, we will be subtracting a shape from this one in a future step. So, the standard border option won’t work here. We’ll use a different technique.

Material Design uses 4px border radius for input fields and a 2px border for the active state. Two shapes will be subtracted to create the border. To keep the border thickness consistent when resizing, the inner shape will be pinned to all sides.

Add the outer rectangle

  • Label name: Border
  • Width: 328; Height: 56
  • Color: #6200EE (or any)
  • Radius: 4

Add the inner rectangle

  • Label name: Surface cutout
  • Width: 324; Height: 52
  • Radius: 2
  • X:2; Y: 2
  • Pin: all sides

Subtract shapes

Subtract Surface cutout from Border layer make one shape. Rename to Surface cutout.

Border thickness and radius does not change, when resizing.

Test your progress

You should be able to resize the symbol without the border thickness or corner radius changing. If they do, ensure Surface cutout layer is pinned on all sides.

Step 3: Add the label cutout

To make the adaptable label and top border, a cutout needs to be created at the top. It always needs to be 11px from the sides, regardless of dimensions of the symbol. A mask will be used to achieve this and will have a fixed height and be pinned so it adapts to the dimensions of the symbol.

Following the technique in Step 2, create a rectangle with the following specs and subtract it from the border shape:

  • Label name: Label cutout
  • Width: 306; Height: 2
  • X: 11; Y: 0
  • Fixed Height
  • Pin: Left, Top, Right

Test your progress

You should be able to resize the shape and the top mask should stay in place.

Step 4: Add label and top border

We can now add the adaptable label and border in the cutout we made in the previous step. As the text length grows, it will push the top border.

How adaptable text works

Before we continue, we need to understand how adaptable text works in Sketch. As text is entered in an override menu, the adjacent element is pushed to keep the distance the same between the two. This only occurs if the text alignment is set to auto and adjacent shape’s height is equal to or less than the text element’s height. Check out Adaptive Text Elements for more details.

The circle moves because its height is less than the text height.
The circle does not move because it’s height is more than the text height.

Add the text layer for label

To push neighboring elements, the text layer can not be a fixed width. Pinning the label and top border will keep them in place, even when the symbol is resized. The label’s alignment must be set to auto to push the top border.

  • Label name: Label
  • X: 16; Y: -9
  • Pin: left and top
  • Color: #6200EE (or any)

Add the top border

The top border is made separate from the rest of the shape so the text can move it. The top border’s width is responding to the label’s width. The top border’s dimension needs to be responsive to the width of the symbol keep the same distance from the override text and the edge of the symbol. Since this is currently not possible in Sketch, we’re going to fake it.

Like the text field, the top border needs to stay at the top of the symbol when resized. It also needs to respond to the length of override text for Label. Since we don’t know the maximum length this symbol will be resized to, we’re going to give the top border a ridiculous length and hide the extra length in the next step.

  • Layer name: Top border
  • X: 56; Y: 0
  • Pin: Top
  • Fixed Height
  • Color: #6200EE (or any)

Test your progress

The distance between the label and top border should be consistent when text is entered in the override menu.

Text pushes the top border.

Step 5: Hide the top border overflow

A mask will be used to hide the top border’s extra length. It will encompass the Label and Top Border. The mask will have the same width as the Label cutout from Step 3 and the same height as the Label layer.

the mask hides additional length of the top border.
  • Add a new rectangle below Top border layer
  • Label: Top border mask
  • X: 11; Y: -9
  • Pin: Left, Top, Right
  • Fixed height
  • Fill color: none
  • Border color: none

Step 6: Add Input text and adaptive cursor

The cursor also needs to move as the override text is entered for the input field.

Add input text layer

Add a text layer as the last layer in the symbol.

  • Label: Input text
  • X: 16; Y: 16
  • Pin: Left, Top and Right
  • Alignment: Auto, left

Add the cursor

Add a rectangle shape as the last layer in the symbol.

  • Width: 1; Height: 17
  • X: 85; Y: 20
  • Pin: Top
  • Fixed Width; Fixed Height

You made it!

Congratulations, if you made it this far, your symbol should look like below. You have made an advanced symbol that adapts to override text and can be resized.

Your symbol should look like this.

These techniques can be used for creating very robust symbols, even with right-aligned text. Since the border is a shape, it can even be used to as a mask to allow the option to change border color.

⬇︎Download the Sketch file.

You may also like my related articles: