Creating an Input Field with an Overlay Icon
Here's how to create an input field with an icon that overlays it using the new responsive engine. So, here's my example and I'm going to build up another one that uses the password field. So, I have a group and I have an input and I have an icon.
Setting Up the Group
Let's build those up. First of all, I need to put in a new group and this is going to be a light parent and you'll see why in a moment. Give it 100% width and then I just need enough height to work with. There we go. And then inside I'm going to place my input and my input is going to be centred but I want to take up the whole space of the group. So, let's give it 100% there and let's try 100% here. There we go.
Adding the Icon
The reason for using a light parent is that allows me to control where my icon sits. So if I draw my icon in there, so this is password so we need a lock and I'm just going to make it square. Oh, that's a little bit too big. Let's go down to 24. Better. And so, I can now control where my icon goes. Few more steps as you can probably notice.
Positioning the Icon
So, let's put the icon on the left. And yeah, not perfect because it overlaps the text which we don't want and also it's a little bit too close to the left hand side. So on the icon, I'm going to give it a margin to the left of say 12. And then in order to stop the text from appearing below the icon, I have to edit the style and increase the horizontal padding.
Adjusting the Padding
Okay, 30 wasn't quite enough. Let's go 40 and preview that. Okay, ah, so it's jumping because I built it using the default standard input style. And that has got a conditional statement. There we go. That takes away, well, it reduces from the 30 figure the horizontal padding. So if I remove those, let's try again.
Final Result and Limitations
Okay, you can see now that I have got my icon, I've got my text input. Now here I'm going to illustrate a short falling of this technique because if I was to just imagine I'm inserting a lot of text. Similarly with the input field, the horizontal padding applies to both the left and the right hand edge. So I'd say ideally I'd want the right hand edge to say go up to here. But because I've applied a 30 pixel padding, it's 30 pixels here and 30 pixels there. But if you're happy with that, then this is a really quick way to achieve the look where you have an icon within an input field.