Representative Martha McSally of Arizona worked hard to carve out a moderate profile since her election in 2014 to a border district seat that had been held for decades by paragons of centrism from both political parties.

But when she entered the Republican primary to succeed the retiring Senator Jeff Flake, Ms. McSally veered right. She gleefully describes her budding relationship with President Trump, a commander in chief she harshly criticized and may not have even voted for in 2016. Ms. McSally, the first female fighter pilot in the Air Force, recalled how at a West Wing meeting with Mr. Trump last year, she made the case for the A-10 Warthog by calling her old jet “a bad-ass airplane with a big gun on it.”

“I have a great relationship with the president — I talk to him like a fighter pilot,” Ms. McSally, a retired colonel, said over a pint of beer here last month.

Ms. McSally represents the evolution of the Republican establishment’s handling of Mr. Trump, from wary detachment to warm embrace, and the delicate dance that Republican politicians face in 2018. Somehow, they must appeal to their Trump-besotted activist base without alienating the broader population of less partisan suburban voters and a growing minority population that has recoiled from the president’s policies and divisive messaging.