If $\ (X,d)\ $ is a complete metric space, and $\ A\ $ is a closed, convex subset of $\ X,\ $ then is $\ A\ $ connected? Transparent note: I edited the question because it wasn't originally what I intended it to be.

If $\ (X,d)\ $ is a complete metric space, and $\ A\ $ is a closed, convex
subset of $\ X,\ $ then is $\ A\ $ connected?

Definition of convex metric space: $(A,d)$ is convex if
\begin{multline*}
(a_1, a_2 \in A \text{ and } a_1 \ne a_2) \implies \\
\exists\ y\in A\setminus\{a_1,a_2\} \text{ such that } d(a_1, y) + d(y,a_2)= d(a_1, a_2).
\end{multline*}
We require $\ A\ $ to be closed because if $\ X=\mathbb{R},\ $ then $\ A = [0,1) \cup (2,3]\ $ is not closed, is convex but is not connected.
I'm not even sure I can prove this if $\ X = \mathbb{R},\ $ although I do know that the closed subsets of $\ \mathbb{R}\ $ are the unions of Cantor sets and closed intervals. But I was actually hoping for a more general, possibly topological approach to the question anyway....
Edit: Here it says that a convex set is always star convex, implying pathwise-connected, which in turn implies connected.
Edit: I have a further question: is $\ A\ $ complete? And I am also not sure if, more generally, a closed connected set in a m.s. is complete? Clearly though, closed and complete does not imply connected, e.g. $ [0,1]\cup [2,3].$ Edit: DanielWainfleet answered this in the comments. The answer is no, e.g. $\ X = A = (0,1]\ $ so yes, the underlying metric space is important.
 A: Let $(X,d)$ be a metric space. A geodesic (the word "geodesic" here is a noun) in $X$ is the image of an isometric map
$$
f: I\to X,
$$
where $I$ is an interval in ${\mathbb R}$.
A metric space is called geodesic (the word "geodesic" here is an adjective) if every two points belong to a common geodesic. Such a space is necessarily path-connected and, hence, connected.
Proposition. Suppose that $(X,d)$ is complete and convex in the sense of your question. Then $(X,d)$ is a geodesic metric space.
Proof. Take two points $x,y\in X$, $D=d(x,y)$. Consider the set $S$ of isometric maps $f: A\to X$, where $A\subset I=[0,D]$ contains $0, D$ and $f(0)=x, f(D)=y$. Define a partial order on $S$ by:
$$
(f: A\to X)\le (g: B\to X) \iff A\subseteq B, f=g|_A.
$$
Zorn's lemma implies that $S$ contains at least one maximal element, i.e. $(f: A\to X)\in S$ such that if  $(f: A\to X)\le (g: B\to X)$, then $A=B$. (Caveat: I am assuming the Axiom of Choice here. I leave it to somebody else to worry about the dependence of validity of the Proposition on the Axiom of Choice.)
Our goal is to prove that for such a maximal element $(f: A\to X)$, $A=I=[0,D]$ (then we would be done).

*

*First, I will prove that for each maximal element $(f: A\to X)$, $A$ is a closed subset of $I$. Indeed, take a sequence $t_n\in A$, $t_n\to t\notin A$. Then $(t_n)$ is a Cauchy sequence, hence, its image $(f(t_n))$ is also Cauchy, hence, by completeness, converges to some $z\in X$. Then we extend $f$ to the point $t$ by $f(t)=z$. The same argument with Cauchy sequences implies that the extended map is continuous at $t$. By continuity of the extension, the new map $f: B=A\cup \{z\}\to X$ is still isometric, hence, $(f: A\to X)< (f: B\to X)$, contradicting maximality of $(f: A\to X)$.


*Suppose that $A\ne I$. Then the complement $I\setminus A$ is a nonempty union of open intervals; take one of these intervals $J=(a,b)$, where $a, b\in A$. By convexity of $(X,d)$, there exists a point $z\in X$ such that $d(f(a), z)+d(z, f(b))=d(f(a), f(b))$ and $z\notin \{f(a), f(b)\}$. Take
$t\in [a,b]$ such that $|t-a|=d(f(a), z)$ and extend $f$ to $t$ by $f(t)=z$. I leave it to you to check that the extended map
$$
f: B=A\cup \{t\}\to X
$$
is still isometric. Since $A\ne B$, we obtain a contradiction with maximality of $(f: A\to X)$. qed
A: This is a partial answer.
We prove that $A$ is connected when $A$ is compact by contradiction:
Suppose $A$ is not connected, which means $A = A_1 \cup A_2$ where $A_1,A_2$ are disjoint closed subsets of $A$. Then $A_1,A_2$ are themselves compact. Consider $d:A_1 \times A_2 \rightarrow \Bbb{R}^+: (p,q) \mapsto d(p,q)$, then $d$ is a continuous function on a compact space, thus achieving its non-zero minimum at $(p_0,q_0) \; (p_0 \ne q_0)$.
Since A is convex, there exists $x \in A \backslash \{ p_0,q_0 \}$ such that $d(p_0,q_0) = d(p_0,x)+d(x,q_0)$, in particular $d(p_0,x)<d(p_0,q_0)$ and $d(x,q_0)<d(p_0,q_0)$. However, $A = A_1 \cup A_2 \Rightarrow x\in A_1$ or $x \in A_2$, either of which contradicts the assumption that $d$ achieves its minimum at $(p_0,q_0)$.
Notice that the proof above doesn't use the completeness of $X$, and by the comment of tomasz what actually matters is the completeness of $A$.
A: Because $A$ is a closed convex subspace of a complete metric space,
$A$ is a complete convex metric space.  We show that any complete
convex metric space $A$ is path-connected, and therefore connected.
(The properties of convexity and completeness will not be used until
near the end of the argument, so most results hold for an arbitrary
metric space $A.$)
The proof uses the
Hausdorff maximal principle,
which is equivalent to the Axiom of Choice (and to Zorn's lemma).
For any metric space $(A, d)$ the function
$d \colon A \times A \to [0, \infty)$ is (uniformly) continuous,
therefore for every pair of points $a, b \in A,$ the function
$$
f_{a, b} \colon A \to [0, \infty), \
x \mapsto d(a, x) + d(x, b) - d(a, b)
$$
is continuous, therefore the set
$$
[[a, b]] = [[b, a]] = f_{a, b}^{-1}(0) =
\{x \in A : d(a, x) + d(x, b) = d(a, b)\}
$$
is closed in $A.$
Lemma 1. For all $w, x, y, z \in A,$
$$
(z \in [[x, y]] \text{ and } w \in [[x, z]]) \iff
(w \in [[x, y]] \text{ and } z \in [[w, y]]).
$$
Proof. Forward implication: if $z \in [[x, y]]$ and
$w \in [[x, z]],$ then
\begin{multline*}
d(x, y) = d(x, z) + d(z, y) = d(x, w) + d(w, z) + d(z, y) \\
\geqslant d(x, w) + d(w, y) \geqslant d(x, y),
\end{multline*}
therefore $d(x, z) + d(z, y) = d(x, y)$ and
$d(w, z) + d(z, y) = d(w, y),$ i.e.,
$w \in [[x, y]]$ and $z \in [[w, y]].$
In view of the symmetry of the $[[a, b]]$ notation, the converse
implication is just the same quantified proposition, in which the
bound variables $(x, w, z, y)$ have been replaced by $(y, z, w, x)$
respectively; and so it is also true. $\ \square$
Lemma 2. For every pair of points $a, b \in A,$ the set
$\{x \in A : b \in [[a, x]]\}$ is closed in $A.$
Proof. The set in question is equal to $g_{a, b}^{-1}(0),$
where
$$
g_{a, b} \colon A \to [0, \infty), \
x \mapsto d(a, b) + d(b, x) - d(a, x).
$$
It is closed because $g_{a, b}$ is continuous. $ \ \square$
Corollary 3. For every pair of points $a, b \in A,$ the set
$[[a, b]] \cup \{x \in A : b \in [[a, x]]\}$ is closed in $A.$
$ \ \square$
The functions $f_{a, b}$ and $g_{a, b}$ were only of temporary use,
but we will be making much use of the continuous function
$$
d_a \colon A \to [0, \infty), \ x \mapsto d(a, x),
$$
which is defined for each point $a \in A.$ For each point $a \in A$
we also define a binary relation $\leqslant_a$ on $A,$ thus:
$$
x \leqslant_a y \iff x \in [[a, y]] \quad (x, y \in A).
$$
Lemma 4. The relation $\leqslant_a$ is a partial order on
$A.$
Proof. Trivially, $x \in [[a, x]],$ so $\leqslant_a$ is
reflexive.  Next, suppose $x \in [[a, y]]$ and $y \in [[a, x]].$
Then
$$
d(x, y) = d(a, y) - d(a, x) = -(d(a, x) - d(a, y)) = -d(x, y),
$$
therefore $d(x, y) = 0,$ therefore $x = y$; so $\leqslant_a$ is
antisymmetric.  Finally, suppose $x \in [[a, y]]$ and
$y \in [[a, z]].$ Then Lemma 1 gives $x \in [[a, z]]$ (also
$y \in [[x, z]]$); so $\leqslant_a$ is transitive. $ \ \square$
Lemma 5. For each point $a \in A,$ the function
$d_a \colon (A, \leqslant_a) \to [0, \infty),$ $x \mapsto d(a, x)$
is order-preserving (isotone).
Proof. If $x \leqslant_a y,$ then
$$
d_a(x) = d(a, x) = d(a, y) - d(x, y) \leqslant d(a, y) = d_a(y).
\quad \square
$$
Applying standard conventions from order theory, we can write
expressions such as "$x <_a y$", meaning $x \leqslant_a y$ and
$x \ne y,$ or "$x \geqslant_a y$", meaning $y \leqslant_a x,$ or
"$x >_a y$", meaning $y <_a x.$
Recall also that a totally ordered subset of an ordered set is
called a chain.
Lemma 6. If $S$ is a chain in $(A, \leqslant_a),$ then the
function $d_a \colon A \to [0, \infty),$ $x \mapsto d(a, x)$
restricts to an isometry $d_a|_S \colon S \to [0, \infty).$ That is:
$$
|d_a(x) - d_a(y)| = d(x, y) \text{ for all } x, y \in S.
$$
Proof. For all $x, y \in S,$ we have either
$x \in [[a, y]],$ in which case $d(x, y) = d_a(y) - d_a(x),$ or
$y \in [[a, x]],$ in which case $d(x, y) = d_a(x) - d_a(y).$
$\ \square$
Corollary 7. If $S$ is a chain in $(A, \leqslant_a),$ then
for all $x, y \in S$:
\begin{gather*}
x = y \iff d_a(x) = d_a(y), \\
x \leqslant_a y \iff d_a(x) \leqslant d_a(y), \\
x <_a y \iff d_a(x) < d_a(y).
\end{gather*}
Proof. The function $d_a$ is injective because it is an
isometry.  The equivalence of $x \leqslant_a y$ with
$d_a(x) \leqslant d_a(y),$ and of $x <_a y$ with $d_a(x) < d_a(y),$
follows from the injectivity of $d_a$ and the fact that $S$ is
totally ordered. $ \ \square$
Lemma 8. If $a, x, y \in A$ and $x \leqslant_a y,$ then
$$
[[x, y]] = \{z \in A : x \leqslant_a z \leqslant_a y\}.
$$
Proof. By Lemma 1, if $x \in [[a, y]]$ and $z \in [[x, y]]$
then $x \in [[a, z]]$ and $z \in [[a, y]].$ This proves that
$[[x, y]] \subseteq \{z \in A : x \leqslant_a z \leqslant_a y\}.$
Also by Lemma 1, if $z \in [[a, y]]$ and $x \in [[a, z]]$ then
$z \in [[x, y]]$ (and $x \in [[a, y]]$). This proves that
$\{z \in A : x \leqslant_a z \leqslant_a y\} \subseteq [[x, y]].$
$\ \square$
Lemma 9. For all $a, b \in A,$ and all $x, y \in [[a, b]],$
$$
x \leqslant_a y \text{ if and only if } y \leqslant_b x.
$$
Proof. By Lemma 1, if $y \in [[a, b]]$ and $x \in [[a, y]],$
then $y \in [[b, x]].$ Also by Lemma 1, if $x \in [[b, a]]$ and
$y \in [[b, x]]$ then $x \in [[y, a]]. \ \square$
By Lemma 9, for every pair of points $a, b \in A,$ the chains of
$([[a, b]], \leqslant_a)$ are the same as the chains of
$([[a, b]], \leqslant_b).$ A set $S \subseteq [[a, b]]$ is a chain
if and only if for all $x, y \in S,$ $x \in [[a, y]]$ or
$y \in [[a, x]].$
Now let points $a, b \in A$ (not necessarily distinct) be chosen and
kept fixed for the rest of the argument.  We will usually work with
the relation $\leqslant_a$ on $[[a, b]],$ rather than $\leqslant_b.$
We write $d(a, b) = \rho \geqslant 0,$ and abuse notation slightly
by restricting the domain and codomain of $d_a,$ so that now
$d_a \colon [[a, b]] \to [0, \rho].$
Lemma 10. If $S$ is a chain in $([[a, b]], \leqslant_a),$
then so is its closure, $\overline{S}.$
Proof. Suppose $S$ is a chain.  For all $x \in S$ and all
$y \in S$ we have
\begin{equation}
\label{4366228:eq:1b}\tag{1}
y \in [[a, x]] \cup \{y \in A : y \in [[a, z]]\}.
\end{equation}
By Corollary 3, the set on the right-hand side of
\eqref{4366228:eq:1b} is closed.  Therefore, it contains the limits
of all convergent sequences of points in $S.$ That is,
\eqref{4366228:eq:1b} also holds for all $x \in S$ and all
$y \in \overline{S}.$ Equivalently, for all such $x$ and $y,$
$$
x \in [[a, y]] \cup \{x \in A : y \in [[a, x]]\}.
$$
By the same argument, it follows that for all $x \in \overline{S}$
and all $y \in \overline{S},$ $x \in [[a, y]]$ or $y \in [[a, x]]$;
that is, $\overline{S}$ is a chain in
$([[a, b]], \leqslant_a). \ \square$
(One could argue more concisely that $S$ is a chain if and only if
$S \times S \subseteq B,$ where $B$ is a closed subset of
$A \times A,$ defined like $f_{a, b}^{-1}(0)$ and $g_{a, b}^{-1}(0)$
above; but the argument's conciseness would probably be offset by
heavy use of notation.)
By the Hausdorff maximal principle, the ordered set
$([[a, b]], \leqslant_a)$ contains a maximal chain. (Indeed, every
chain in an ordered set is contained in a maximal chain.) From now
on, let $S$ be a maximal chain in $([[a, b]], \leqslant_a).$
Lemma 11. $S$ is closed in $A.$
Proof. This follows from Lemma 10 together with the maximality
of $S. \ \square$
Lemma 12. $\{a, b\} \subseteq S.$
Proof. Let $S' = S \cup \{a, b\}.$ We have $b \in [[a, b]],$
and for all $x \in S,$ $a \in [[a, x]]$ and $x \in [[a, b]].$ Hence
$S'$ is a chain in $[[a, b]].$ But $S$ is maximal, therefore
$S' = S,$ therefore $\{a, b\} \subseteq S. \ \square$
We establish the path-connectedness of $A$ by constructing a
bijective isometry $\gamma\colon[0, \rho] \to S$ such that
$\gamma(0) = a$ and $\gamma(\rho) = b.$ It is enough to show that
the isometry $d_a|_S \colon S \to [0, \rho]$ from Lemma 6 (with the
newly restricted codomain) is surjective, therefore bijective; then
we can take $\gamma = (d_a|_S)^{-1}.$
Let $\tau$ be any real number such that
$0 \leqslant \tau \leqslant \rho.$ Then $S = L \cup R,$ where
\begin{align*}
L & = \{x \in S : \ d_a(x) \leqslant \tau\}, \\
R & = \{y \in S : \ d_a(y) \geqslant \tau\}.
\end{align*}
Neither of these closed subsets of $A$ is empty, because $a \in L$
and $b \in R.$ Define
\begin{gather*}
\xi  = \sup(d_a(L)) \in [0, \tau], \\
\eta = \inf(d_a(R)) \in [\tau, \rho].
\end{gather*}
We prove first that there exist $x \in L$ such that
$d_a(x) = \xi,$ and $y \in R$ such that $d_a(y) = \eta.$
To this end, choose sequences $(x_n)_{n\geqslant1}$ in $L$ and
$(y_n)_{n\geqslant1}$ in $R$ such that $\lim_nd_a(x_n) = \xi$
and $\lim_nd_a(y_n) = \eta.$ Because
$d_a|_S \colon S \to [0, \rho]$ is an isometry, and
$(d_a(x_n))$ and $(d_a(y_n))$ are Cauchy sequences in
$[0, \rho],$ the sequences $(x_n)$ and $(y_n)$ are Cauchy in $S.$
Therefore, because the metric space $A$ is complete, and the subsets
$L$ and $R$ are closed, the limit $x = \lim_nx_n$ exists in $L,$ and
the limit $y = \lim_ny_n$ exists in $R$ (abusing notation slightly).
Because $d_a$ is continuous,
\begin{align*}
d_a(x) & = \lim_nd_a(x_n) = \xi, \\
d_a(y) & = \lim_nd_a(y_n) = \eta.
\end{align*}
We have $d_a(x) \leqslant d_a(y),$ whence by Corollary 7,
$x \leqslant_a y.$ By the convexity of $A,$ if $x \ne y,$ then there
exists $z \in A$ such that $z \in [[x, y]]$ and $z \ne x$ and
$z \ne y.$ By Lemma 8, $x <_a z <_a y.$ By Corollary 7 again, for
all $w \in S$ we have either (i) $w \leqslant_a x <_a z,$ whence
$w \in [[a, z]],$ or (ii) $z <_a y \leqslant_a w,$ whence
$z \in [[a, w]].$ Therefore $S \cup \{z\}$ is a chain in
$([[a, b]], \leqslant_a).$ Because $S$ is maximal, it follows that
$z \in S.$ But this is a contradiction, because it has just been
shown that for all $w \in S,$ either $w <_a z$ or $z <_a w$.
Therefore, the hypothesis $x \ne y$ is false, i.e., $x = y.$
Therefore $\xi = \eta.$ But $\xi \leqslant \tau \leqslant \eta,$
therefore $d_a(x) = \tau = d_a(y).$ So $d_a|_S$ is surjective, and
the proof is complete.
