A judge praised the efforts of the 26-year-old, who cannot be named for legal reasons, for her “wholly admirable” progress in battling a drug problem.
The toddler has been cared for by her aunt and uncle since she was born and the judge said the arrangement should be made permanent.
The mother, from Midlothian, had two children by a long-term partner, with her seven-year-old son being looked after by her mother.
Midlothian Council raised an action at the Court of Session in Edinburgh seeking to have the adoption of the child by the aunt and uncle sanctioned.
The mother opposed the move, insisting a child should stay with the natural mother.
Lord Malcolm said: “What the child needs now is a permanent, secure and stable home.”