How to adapt underlined button to text length ? (complex button)

Use Auto Layout, Absolute position and Constraints. You can see an example here: Figma Auto Layout Playground.