Making a shape Wider when more Text is there

This is probably something pretty easy to do, I just don’t know how you’d do it.

I’ve got a ‘tab’, and I want it to be wider/shorter based on how much text is in it.

The text is being generated dynamically, so i need the width of the shape, which will sit behind it, to change accordingly.

Anybody got an idea how this can be done?

Thanks!